โ† All MATLAB Flashcard Decks

Functions and Flow Control 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 Functions and Flow Control flashcards as text
  1. What keyword is used to terminate a loop or switch statement early in MATLAB?

    Answer: break

    The `break` statement immediately exits the innermost for or while loop.

  2. What does the `nargin` function return inside a MATLAB function?

    Answer: Number of input arguments passed by the caller

    `nargin` returns the number of input arguments actually provided when the function was called.

  3. Which syntax correctly defines a MATLAB function that returns two output values?

    Answer: function [a, b] = myfunc(x)

    Multiple return values are declared with square brackets: `function [a, b] = myfunc(x)`.

  4. In a `switch` statement, what block handles all cases not matched by any `case`?

    Answer: otherwise

    The `otherwise` block in a MATLAB switch statement handles unmatched cases.

  5. What happens when `continue` is used inside a for loop in MATLAB?

    Answer: Skips to the next iteration

    `continue` skips the remaining statements in the current iteration and proceeds to the next one.

  6. Which MATLAB function allows you to call a function by its name stored as a string?

    Answer: feval()

    `feval('funcname', args)` evaluates the named function with the given arguments.

  7. What is the output of the following code? for k = 1:3 if k == 2, continue; end disp(k) end

    Answer: 1 3

    `continue` skips `disp(k)` when k==2, so only 1 and 3 are displayed.