Surf from a numerical array

1 次查看(过去 30 天)
Mat Hunt
Mat Hunt 2024-2-26
移动Voss 2024-2-26
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.

采纳的回答

Voss
Voss 2024-2-26
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 个评论
Voss
Voss 2024-2-26
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
Voss 2024-2-26
移动:Voss 2024-2-26
"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)
t = 1×10
0.0100 0.0111 0.0122 0.0133 0.0144 0.0156 0.0167 0.0178 0.0189 0.0200
% 15 x values ranging from 100 to 200
x = linspace(100,200,15)
x = 1×15
100.0000 107.1429 114.2857 121.4286 128.5714 135.7143 142.8571 150.0000 157.1429 164.2857 171.4286 178.5714 185.7143 192.8571 200.0000
% 15-by-10 matrix u
u = exp(t.*x.')
u = 15×10
2.7183 3.0377 3.3947 3.7937 4.2395 4.7377 5.2945 5.9167 6.6120 7.3891 2.9195 3.2886 3.7044 4.1727 4.7003 5.2945 5.9638 6.7178 7.5671 8.5238 3.1357 3.5603 4.0423 4.5897 5.2111 5.9167 6.7178 7.6274 8.6601 9.8327 3.3679 3.8544 4.4111 5.0483 5.7775 6.6120 7.5671 8.6601 9.9111 11.3427 3.6173 4.1727 4.8135 5.5527 6.4054 7.3891 8.5238 9.8327 11.3427 13.0845 3.8851 4.5174 5.2526 6.1075 7.1016 8.2574 9.6014 11.1640 12.9811 15.0938 4.1727 4.8905 5.7318 6.7178 7.8734 9.2278 10.8152 12.6756 14.8561 17.4117 4.4817 5.2945 6.2547 7.3891 8.7291 10.3123 12.1825 14.3919 17.0020 20.0855 4.8135 5.7318 6.8253 8.1274 9.6779 11.5241 13.7226 16.3406 19.4579 23.1700 5.1699 6.2053 7.4479 8.9395 10.7297 12.8785 15.4575 18.5531 22.2685 26.7281
% plot the surface
surf(t,x,u)
xlabel('t')
ylabel('x')
zlabel('u')

请先登录,再进行评论。

更多回答(1 个)

Sufiyan
Sufiyan 2024-2-26
I believe this is similar to changing the limits on the axis scale to different values or rescaling the axis.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by