← All MATLAB Flashcard Decks

Variables and Workspace Interaction Flashcards

7 cards from real MATLAB practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Variables and Workspace Interaction flashcards as text
  1. What does the `-v7.3` flag do in the `save` command?

    Answer: Enables saving variables larger than 2 GB using HDF5 format

    The `-v7.3` flag saves in HDF5-based format, which supports variables exceeding 2 GB, unlike the default format.

  2. How do you capture the contents of a .mat file into a struct without polluting the workspace?

    Answer: s = load('file.mat')

    When `load` is called with an output argument in function syntax, it returns a struct whose fields correspond to the saved variables.

  3. What is the class of a variable created by `x = 5` in MATLAB by default?

    Answer: double

    Numeric literals in MATLAB default to `double` (64-bit floating-point) unless explicitly cast to another type.

  4. Which function returns the number of bytes a variable occupies in memory?

    Answer: whos('x') — check Bytes column

    `whos` displays the bytes column for each variable; programmatically, `s = whos('x'); s.bytes` gives the byte count.

  5. What is the effect of suppressing output with a semicolon on a variable assignment like `x = 10;`?

    Answer: The variable is stored but not printed to the Command Window

    A trailing semicolon suppresses the echo of the assignment to the Command Window but the variable is still created in the workspace.

  6. Which of the following correctly declares a global variable in a MATLAB function?

    Answer: global x; x = 5;

    The `global` keyword must appear on its own declaration line before the variable is used; assignment follows separately.

  7. What happens when you call `clear x` inside a function that has `x` declared as `persistent`?

    Answer: The persistent value is erased

    `clear x` inside the function clears the persistent variable `x`; to clear persistent variables from outside, you use `clear functionName`.