meshgrid plotting how to speficy x-axis and y-axis values?
12 次查看(过去 30 天)
显示 更早的评论
I create a meshgrid and calculate a function camel. When I plot it, it displays indices, not X and Y values on the plot axes. How can I make it show the X and Y values on the plot axes instead?
[X,Y] = meshgrid(-3:0.1:3); camel = (4-2.1*X.^2+X.^4/3).*X.^2+X.*Y+4*(Y.^2-1).*Y.^2; imagesc(camel)
0 个评论
回答(1 个)
Star Strider
2016-10-14
I’m not certain what you want to do.
Try this:
[X,Y] = meshgrid(-3:0.1:3);
camel = (4-2.1*X.^2+X.^4/3).*X.^2+X.*Y+4*(Y.^2-1).*Y.^2;
figure(1)
surf(X,Y,camel)
grid on
4 个评论
Star Strider
2016-10-14
My pleasure.
The transition of my code to use contour (or here contourf) is straightforward:
[X,Y] = meshgrid(-3:0.1:3);
camel = (4-2.1*X.^2+X.^4/3).*X.^2+X.*Y+4*(Y.^2-1).*Y.^2;
figure(1)
[C,hs] = contourf(X,Y,camel);
grid on
axis equal
view([0, 90])
set(hs, 'LineStyle','none')
To use imagesc requires a couple tweaks:
x = -3:0.1:3;
y = x;
figure(2)
imagesc(x,y,camel)
axis image
Experiment with the resolution of the meshgrid argument and ‘x’ (use the linspace function) to vary the resolution easily.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!