← All MATLAB Flashcard Decks

Programming and Scripting 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 Programming and Scripting flashcards as text
  1. How do you preallocate a 100x100 matrix of zeros in MATLAB?

    Answer: M = zeros(100,100)

    zeros(m,n) creates an m-by-n matrix of double-precision zeros, which is the standard preallocating technique.

  2. In MATLAB, what does the colon operator 1:2:10 generate?

    Answer: [1 3 5 7 9]

    The syntax start:step:end generates [1 3 5 7 9] — values from 1 to 10 with step 2.

  3. Which statement correctly defines a function handle in MATLAB?

    Answer: f = @(x) x^2

    The '@(x) x^2' syntax creates an anonymous function handle in MATLAB.

  4. What does 'fieldnames(S)' return when S is a MATLAB structure?

    Answer: A cell array of field name strings

    fieldnames() returns a cell array of character vectors, each containing one field name of the struct.

  5. Which MATLAB function evaluates a string as a MATLAB expression?

    Answer: eval()

    eval() executes the MATLAB code contained in a character vector or string.

  6. How does 'continue' differ from 'break' inside a MATLAB loop?

    Answer: continue skips to the next iteration; break exits the loop

    'continue' skips the rest of the current iteration and moves to the next one, while 'break' exits the loop entirely.

  7. What is the purpose of the 'inputParser' class in MATLAB?

    Answer: Validating and parsing function input arguments with named parameters and defaults

    inputParser provides a systematic way to define required, optional, and name-value pair arguments with validation for functions.