Bird
0
0

What will be the output of the following MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - File I/O
What will be the output of the following MATLAB code?
x = 5; y = 10; save('test.mat', 'x'); clear; load('test.mat'); disp(y);
A10
B5
CError: Undefined function or variable 'y'.
D0
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the save and clear commands

    Only variable x is saved. The clear command removes all variables from workspace.
  2. Step 2: Load restores only x, not y

    After loading, only x exists. y is undefined, so disp(y) causes an error.
  3. Final Answer:

    Error: Undefined function or variable 'y'. -> Option C
  4. Quick Check:

    Only saved variables load back; others cause error [OK]
Quick Trick: Only saved variables are restored after load [OK]
Common Mistakes:
  • Assuming all variables reload
  • Ignoring clear effect
  • Expecting default zero for missing variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes