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 is the difference between `==` and `isequal()` when comparing arrays in MATLAB?
Answer: `==` compares element-wise and returns an array; `isequal()` checks if arrays are identical and returns a scalar
`==` performs element-wise comparison returning a logical array, while `isequal()` returns a single true/false for whole-array equality.
What happens when you assign `s(5).x = 10` to a struct `s` that only has elements 1-3?
Answer: Elements 4 and 5 are created; element 4 has empty fields and element 5 has x=10
MATLAB auto-expands struct arrays; intermediate elements (4) are created with empty (`[]`) field values.
Which syntax correctly creates a string array (not cell array of chars) in MATLAB R2017a+?
Answer: string({"hello","world"})
string({...}) converts a cell array of chars into a string array; double-quoted literals like "hello" also create string scalars.
What does `sparse()` create in MATLAB?
Answer: A matrix that only stores nonzero elements to save memory
`sparse()` creates a sparse matrix representation that stores only nonzero values and their indices, saving memory for large matrices with few nonzeros.
How do you find all keys in a `containers.Map` object named `m`?
Answer: keys(m)
The `keys(m)` function returns a cell array of all keys in a `containers.Map` object.
What is the result of `size(struct('a',1,'b',2))` in MATLAB?
Answer: [1 1]
A single struct is a 1x1 struct array, so `size()` returns `[1 1]` regardless of the number of fields.
Which MATLAB function converts a string `'3.14'` to the numeric double value 3.14?
Answer: str2double()
`str2double()` converts a string or char array representing a number to a double-precision value.