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
Which MATLAB function returns the size of an array along a specific dimension?
Answer: size(A, dim)
size(A, dim) returns the length of array A along the specified dimension.
What does the tilde '~' symbol mean when used as a function output argument in MATLAB?
Answer: The output is ignored/discarded
Using '~' as a placeholder output argument tells MATLAB to discard that output without storing it.
In MATLAB, which type of file has the '.m' extension and contains only commands (no function definition)?
Answer: Script file
A script file (.m) contains a sequence of MATLAB commands that execute in the calling workspace, unlike function files which define functions.
What does 'cellfun(@numel, C)' return for a cell array C?
Answer: A numeric array where each element is the number of elements in the corresponding cell
cellfun applies a function to each cell and by default returns a numeric array of the scalar results.
How do you add a new field 'age' with value 30 to an existing structure variable 'person'?
Answer: person.age = 30
MATLAB adds a new field to a struct using dot notation assignment: person.age = 30.
Which keyword ends a function, for loop, while loop, if block, and switch block in MATLAB?
Answer: end
The 'end' keyword terminates all control flow constructs and function definitions in MATLAB.
What is the result of logical short-circuit evaluation using '&&' vs '&' in MATLAB?
Answer: '&&' short-circuits scalar operands and skips evaluating the right side if the left is false; '&' always evaluates both sides element-wise
'&&' performs short-circuit AND on scalars, skipping the right operand when the left is false; '&' always evaluates both operands element-wise.