← All MATLAB Flashcard Decks

Matrix and Array Operations 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 Matrix and Array Operations flashcards as text
  1. What does the MATLAB expression `A(:, 2)` return for a 3×4 matrix A?

    Answer: The second column of A

    The colon in the row index selects all rows, so `A(:, 2)` returns the entire second column as a column vector.

  2. Which MATLAB function returns the number of elements in an array regardless of its dimensions?

    Answer: numel(A)

    `numel(A)` returns the total number of elements, equivalent to prod(size(A)).

  3. What is the result of `[1 2; 3 4] .^ 2` in MATLAB?

    Answer: [1 4; 9 16]

    The element-wise power operator `.^` squares each element individually, yielding [1 4; 9 16].

  4. How do you delete the third row of matrix A in MATLAB?

    Answer: A(3, :) = []

    Assigning `[]` to a full row slice `A(3, :)` removes that row from the matrix.

  5. What does `linspace(0, 1, 5)` produce?

    Answer: [0 0.25 0.5 0.75 1]

    `linspace(0, 1, 5)` creates 5 linearly spaced values from 0 to 1 inclusive: [0, 0.25, 0.5, 0.75, 1].

  6. In MATLAB, what is the output of `size([1 2 3; 4 5 6])`?

    Answer: [2 3]

    `size` returns a vector [rows, cols], so a 2×3 matrix returns [2 3].

  7. Which operator performs matrix multiplication (not element-wise) in MATLAB?

    Answer: *

    The `*` operator performs standard matrix multiplication, while `.*` performs element-wise multiplication.