Bird
0
0

What is the issue with the following MATLAB code?

medium📝 Debug Q6 of 15
MATLAB - 2D Plotting
What is the issue with the following MATLAB code?
x = 1:4;
y = [3 6 9 12 15];
plot(x, y)
AThe plot function cannot plot numeric vectors
BThe plot function requires y to be a column vector
CVectors x and y have different lengths
DThere is no issue; the code will run correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check vector lengths

    Vector x has 4 elements, but vector y has 5 elements.
  2. Step 2: Understand plot requirements

    MATLAB's plot function requires x and y to be the same length to plot corresponding points.
  3. Final Answer:

    Vectors x and y have different lengths -> Option C
  4. Quick Check:

    Length mismatch causes error [OK]
Quick Trick: x and y must have equal length [OK]
Common Mistakes:
  • Assuming plot accepts vectors of different lengths
  • Thinking y must be a column vector
  • Ignoring vector size mismatch errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes