Variables and Workspace Interaction 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 Variables and Workspace Interaction flashcards as text
Which command removes ALL variables from the MATLAB workspace without prompting for confirmation?
Answer: clear
`clear` (with no arguments) removes all variables from the current workspace silently.
What does the `whos` command display that `who` does not?
Answer: Size, bytes, and class of each variable
`whos` provides detailed information including size, allocated bytes, and data class, while `who` lists only variable names.
After executing `x = 5; y = x; x = 10;`, what is the value of `y`?
Answer: 5
MATLAB uses value semantics for numeric types, so `y` receives a copy of `x` at the time of assignment and is unaffected by later changes to `x`.
Which function checks whether a variable named 'myVar' exists in the current workspace?
Answer: exist('myVar', 'var')
`exist('myVar', 'var')` returns 1 if `myVar` is defined in the current workspace and 0 otherwise.
What is the result of assigning `A = [1 2; 3 4]; B = A;` and then modifying `B(1,1) = 99;`?
Answer: A remains [1 2; 3 4]
MATLAB uses copy-on-write semantics, so modifying `B` creates a separate copy, leaving `A` unchanged.
What command saves only the variables `x` and `y` to a file named 'data.mat'?
Answer: save data.mat x y
`save data.mat x y` saves only the specified variables `x` and `y` to 'data.mat'.
How do you load only the variable 'score' from 'results.mat' into the workspace?
Answer: Both A and B are valid
Both the command syntax `load results.mat score` and the function syntax `load('results.mat', 'score')` are valid in MATLAB.