Surf from a numerical array
4 views (last 30 days)
Show older comments
Suppose I solve a PDE and obtain a solution in 2D say . If I do surf(u) I get a picture of the whole thing. Can I change the values of the axis to correspond to the actual values of interest? Currently the axis values just represent the number of data points, so I want to change that to actual values of interest.
0 Comments
Accepted Answer
Voss
on 26 Feb 2024
Yes. You can use the xlim and ylim functions to set the axes limits to the actual region of interest.
Example:
% some matrix
z = peaks(100);
% the whole thing
figure();
surf(z)
xlabel('x')
ylabel('y')
zlabel('z')
% the actual region of interest
figure();
surf(z)
xlabel('x')
ylabel('y')
zlabel('z')
xlim([30 75])
ylim([50 90])
7 Comments
Voss
on 26 Feb 2024
Not necessarily. In surf(X,Y,Z) X and Y can be vectors or matrices.
meshgrid would be useful for constructing matrix X and Y from vector X and Y, but you can use the vectors directly in surf.
Voss
on 26 Feb 2024
Moved: Voss
on 26 Feb 2024
"Currently the axis values just represent the number of data points, so I want to change that to actual values of interest."
Specify the values of interest in the call to surf.
Example:
% 10 t values ranging from 0.01 to 0.02
t = linspace(0.01,0.02,10)
% 15 x values ranging from 100 to 200
x = linspace(100,200,15)
% 15-by-10 matrix u
u = exp(t.*x.')
% plot the surface
surf(t,x,u)
xlabel('t')
ylabel('x')
zlabel('u')
More Answers (1)
Sufiyan
on 26 Feb 2024
I believe this is similar to changing the limits on the axis scale to different values or rescaling the axis.
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!