Bird
0
0

What will be the output of the following MATLAB code?

medium📝 Predict Output Q13 of 15
MATLAB - 2D Plotting
What will be the output of the following MATLAB code?
x = 1:3;
y = [2 4 6];
plot(x, y)
AA plot with points (1,2), (2,4), (3,6) connected by lines.
BA plot with points (2,1), (4,2), (6,3) connected by lines.
CAn error because x and y have different lengths.
DA plot with points (1,1), (2,2), (3,3) connected by lines.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze vectors x and y

    x is [1 2 3] and y is [2 4 6], both have length 3, so they can be plotted against each other.
  2. Step 2: Understand plot output

    The plot will connect points (1,2), (2,4), and (3,6) with lines.
  3. Final Answer:

    A plot with points (1,2), (2,4), (3,6) connected by lines. -> Option A
  4. Quick Check:

    plot(x, y) = points (1,2), (2,4), (3,6) [OK]
Quick Trick: Match x and y points by position in vectors [OK]
Common Mistakes:
  • Mixing up x and y coordinates
  • Assuming error due to vector length mismatch
  • Confusing point coordinates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes