Bird
0
0

What will be the output of this MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - 2D Plotting
What will be the output of this MATLAB code?
x = 0:0.5:2;
plot(x, x.^2);
hold on;
plot(x, x+1);
AA single figure with two lines: one quadratic and one linear.
BTwo separate figures each with one line.
COnly the linear plot is shown, quadratic is erased.
DAn error because <code>hold on</code> is used incorrectly.
Step-by-Step Solution
Solution:
  1. Step 1: Plot quadratic function

    The first plot draws y = x^2.
  2. Step 2: Use hold on and plot linear function

    hold on keeps the first plot visible, so the second plot adds y = x + 1 on the same figure.
  3. Final Answer:

    A single figure with two lines: one quadratic and one linear. -> Option A
  4. Quick Check:

    hold on adds plots together = D [OK]
Quick Trick: Use hold on to combine plots in one figure [OK]
Common Mistakes:
  • Expecting separate figures without figure command
  • Thinking second plot erases first without hold on
  • Assuming hold on causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes