meshgrid plotting how to speficy x-axis and y-axis values?
12 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 14 Oct 2016
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 Comments
Star Strider
on 14 Oct 2016
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!