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
What happens when you concatenate a `double` array and a `single` array using `[]` in MATLAB?
Answer: The result is single
When concatenating single and double arrays, MATLAB converts the result to single (lower precision wins to save memory).
How do you add a new field `age` to an existing struct `s`?
Answer: s.age = 30
Simply assigning `s.age = 30` dynamically adds the field `age` to the struct.
What does `fieldnames(s)` return for a struct `s` with fields `x` and `y`?
Answer: {'x';'y'}
`fieldnames()` returns a cell array of character vectors containing the field names.
Which statement correctly creates an empty cell array of size 3x2 in MATLAB?
Answer: C = cell(3,2)
The `cell(m,n)` function creates an m-by-n cell array where every cell contains an empty matrix.
What is the purpose of `int8` versus `uint8` in MATLAB?
Answer: int8 stores signed integers (-128 to 127); uint8 stores unsigned integers (0 to 255)
`int8` represents signed 8-bit integers (-128 to 127), while `uint8` represents unsigned 8-bit integers (0 to 255).
How do you convert a character array `'hello'` to a string object in MATLAB R2016b+?
Answer: string('hello')
The `string()` function converts character arrays, cell arrays of chars, and other types to string objects.
What does `numel(C)` return for a 2x3 cell array `C`?
Answer: 6
`numel()` returns the total number of elements, which for a 2x3 array is 2×3 = 6.