โ† All MATLAB Flashcard Decks

Data Types and Structures 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 Data Types and Structures flashcards as text
  1. What does the MATLAB function `iscell()` return when passed a cell array?

    Answer: 1

    `iscell()` returns logical 1 (true) if the input is a cell array, and 0 otherwise.

  2. Which MATLAB syntax correctly accesses the second element of a cell array `C`?

    Answer: C{2}

    Curly braces `C{2}` extract the contents of a cell, while parentheses `C(2)` return a cell array subset.

  3. What is the default numeric data type for variables created by typing a number in MATLAB?

    Answer: double

    MATLAB defaults to `double` (64-bit floating point) for all numeric literals unless explicitly cast.

  4. How do you create a 1x3 struct array named `s` with field `name` in MATLAB?

    Answer: s = struct('name', {'Alice','Bob','Carol'})

    Passing a cell array of values to `struct()` automatically creates a struct array with one element per cell.

  5. What does `typecast(int32(1), 'uint32')` return in MATLAB?

    Answer: The bit pattern of int32(1) reinterpreted as uint32

    `typecast` reinterprets the underlying bit pattern without converting the value, so int32(1) becomes uint32(1) since the bits are identical.

  6. Which function converts a numeric array to a logical array in MATLAB?

    Answer: logical()

    `logical()` converts a numeric array to logical type, where 0 becomes false and any nonzero becomes true.

  7. What is the result of `class(uint8(200) + uint8(100))` in MATLAB?

    Answer: uint8

    Arithmetic on uint8 operands produces a uint8 result, with the value saturating at 255 instead of overflowing.