Surface plot generation for a 3-variable function

조회 수: 7 (최근 30일)
Manu M
Manu M 2019년 4월 8일
답변: VBBV 2023년 6월 3일
Greetings, Could you please advise how to generate a surface plot for a 3- variable function. (The meshgrid and function are working properly but the surf() function keeps throwing out error and no graph appears)
u=1000:4:3000;
v=400:1.6:1200;
w=0.25:0.001:0.75;
[x,y,z]=meshgrid(u,v,w);
g=x*x+y*y-z*z;
surf(u,v,g)
Thanks!
Also Could you let me know how to plot surf(u,w,g) and surf (v,w,g) in separate graphs.

답변 (2개)

Walter Roberson
Walter Roberson 2019년 4월 8일
surf can only be used for rectangular (2d) data arrays.
For 3d data arrays your choices include
  • isosurface
  • slice
  • volumeviewer or underlying functionality can be called directly in very recent releases
  • vol3d v2 from File Exchange
  • scatter3 and encode the value by color or size

VBBV
VBBV 2023년 6월 3일
Try to use a for loop to plot the resulting expression in 3rd dimension as shown below since surf function plots 2D matrices only
u=100:5:300;
v=40:1.6:120;
w=0.25:0.1:0.75;
[x,y,z]=meshgrid(u,v,w);
g=x.^2+y.^2-z.^2;
hold on
for k = 1:length(size(z,3))
surf(u,v,g(:,:,k))
end
colorbar
shading interp
view(3)
grid

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by