Bird
0
0

Find the error in this MATLAB code:

medium📝 Debug Q7 of 15
MATLAB - 3D Plotting and Visualization
Find the error in this MATLAB code:
[X,Y] = meshgrid(-1:1, -1:1); Z = X.^2 + Y.^2; contour(X, Y, Z, 'LevelList', [1 2 3]);
AThe vectors for meshgrid are too small
B'LevelList' is not a valid property for contour function
CZ calculation uses incorrect element-wise operators
DNo error, code runs and plots correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check contour property names

    MATLAB contour does not support 'LevelList' property. Levels are specified positionally, e.g., contour(X, Y, Z, [1 2 3]).
  2. Step 2: Verify other parts

    Meshgrid vectors and Z calculation are correct with element-wise operators.
  3. Final Answer:

    'LevelList' is not a valid property for contour function -> Option B
  4. Quick Check:

    Use correct property names for contour [OK]
Quick Trick: Check property names carefully for contour vs contourf [OK]
Common Mistakes:
  • Using unsupported property names
  • Confusing contour and contourf properties
  • Assuming small meshgrid vectors cause errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes