โ† All MATLAB Flashcard Decks

Script and Function Creation 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 Script and Function Creation flashcards as text
  1. What is the correct way to define a function that returns multiple output values in MATLAB?

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

    Multiple return values are declared in square brackets on the left side of the assignment in the function signature.

  2. Which command clears all variables from the MATLAB workspace at the start of a script?

    Answer: clear all

    `clear all` removes all variables, globals, and functions from the workspace.

  3. In a MATLAB function file, where must the primary function definition appear?

    Answer: At the top of the file before any other code

    MATLAB requires the primary function to be the first function defined in a function file.

  4. What happens when a MATLAB script is run and a variable with the same name already exists in the workspace?

    Answer: The existing variable is overwritten

    Scripts share the caller's workspace, so running a script overwrites any existing variable of the same name.

  5. Which keyword is used to exit a function early in MATLAB before reaching the end?

    Answer: return

    `return` immediately exits the current function and returns control to the calling code.

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

    Answer: The number of input arguments passed by the caller

    `nargin` returns the actual count of input arguments provided when the function was called.

  7. A local function defined inside a function file is accessible:

    Answer: Only by the functions in the same file

    Local (subfunctions) are scoped to the file they are defined in and cannot be called from outside.