Bird
0
0

Identify the error in this MATLAB code for a scatter plot:

medium📝 Debug Q14 of 15
MATLAB - 2D Plotting
Identify the error in this MATLAB code for a scatter plot:
x = 1:4;
y = [5 6 7];
scatter(x, y)
AVectors x and y have different lengths causing an error
Bscatter requires a third argument for size
Cscatter cannot plot numeric vectors
DNo error; code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check vector lengths

    Vector x has length 4, but y has length 3, which is invalid for scatter.
  2. Step 2: Understand scatter input requirements

    Scatter requires x and y to be the same length to plot pairs of points.
  3. Final Answer:

    Vectors x and y have different lengths causing an error -> Option A
  4. Quick Check:

    Length mismatch in x,y vectors = error [OK]
Quick Trick: x and y must be same length for scatter [OK]
Common Mistakes:
  • Assuming scatter auto-fixes length mismatch
  • Thinking size argument is mandatory
  • Believing scatter can't plot numeric data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes