How to use meshgrid and contour
32 views (last 30 days)
Show older comments
x=-2*pi:pi/100:2*pi;
y=-2*pi:pi/100:2*pi;
[X,Y]=meshgrid(x,y);
Z=(sin(2*X).^2)+(cos(2*Y).^2);
figure
contour3(X,Y,Z)
Accepted Answer
Star Strider
on 1 Mar 2019
I don’t know what you mean by ‘not working’.
This (slighty variation on your posted code) works, and shows the contour3 lines on the mesh plot surface:
x=-2*pi:pi/100:2*pi;
y=-2*pi:pi/100:2*pi;
[X,Y]=meshgrid(x,y);
Z=(sin(2*X).^2)+(cos(2*Y).^2);
figure
mesh(X,Y,Z)
hold on
contour3(X,Y,Z, 'r', 'LineWidth',1)
hold off
grid on
What result do you want if it’s other than this?
0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!