โ† All MATLAB Flashcard Decks

Environment and Syntax 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 Environment and Syntax flashcards as text
  1. What is the effect of using `global x` inside a MATLAB function?

    Answer: Shares `x` across the base workspace and all functions that declare it global

    Declaring a variable `global` allows multiple functions and the base workspace to share the same instance of that variable.

  2. Which MATLAB command saves all current workspace variables to a `.mat` file named `data.mat`?

    Answer: save('data.mat')

    `save('data.mat')` writes all workspace variables to a binary `.mat` file, which can later be restored with `load`.

  3. What does `nargin` return inside a MATLAB function?

    Answer: The actual number of input arguments passed by the caller

    `nargin` returns the count of input arguments that were actually provided when the function was called, enabling optional-argument patterns.

  4. In MATLAB, what does the `end` keyword represent when used as an array index?

    Answer: The last valid index of that dimension

    When used inside indexing parentheses, `end` automatically resolves to the last index of the relevant array dimension.

  5. Which of the following correctly creates a row vector of integers from 1 to 10 with a step of 2?

    Answer: 1:2:10

    The colon operator `start:step:end` generates a vector; `1:2:10` produces [1 3 5 7 9].

  6. What is the result of `isinf(1/0)` in MATLAB?

    Answer: true (1)

    MATLAB evaluates `1/0` as `Inf` without error, and `isinf(Inf)` returns logical 1.

  7. What does the `persistent` keyword do in a MATLAB function?

    Answer: Preserves the variable's value between calls to the function

    A `persistent` variable retains its value between successive calls to the same function, similar to a static local variable in C.