Bird
0
0

What is wrong with this MATLAB code for plotting a 3D surface?

medium📝 Debug Q7 of 15
MATLAB - 3D Plotting and Visualization
What is wrong with this MATLAB code for plotting a 3D surface?
[X,Y] = meshgrid(-2:2, -2:2);
Z = X.^2 + Y.^2;
surf(X, Z);
Asurf requires three arguments: X, Y, and Z.
Bmeshgrid is used incorrectly.
CZ calculation is invalid.
Dsurf cannot plot squared values.
Step-by-Step Solution
Solution:
  1. Step 1: Check surf function arguments

    surf requires X, Y, and Z matrices to plot a 3D surface properly.
  2. Step 2: Identify missing argument

    The code passes only X and Z, missing Y, causing an error.
  3. Final Answer:

    surf requires three arguments: X, Y, and Z. -> Option A
  4. Quick Check:

    surf needs X, Y, Z inputs [OK]
Quick Trick: Always provide X, Y, and Z to surf for 3D plots [OK]
Common Mistakes:
  • Omitting Y argument in surf
  • Misusing meshgrid
  • Thinking surf can't plot squared values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes