isosurface函数MATLAB用法

时间:2011-10-06 22:38:04

标签: matlab 3d plot

您可以给我一个如何在MATLAB中使用isosurface函数的简单示例。 键入help isosurface时给出的示例非常令人困惑。在谷歌搜索并没有帮助,因为没有人在任何地方给出简单的例子。所有这些都使用预定义的函数 flow

对于初学者,假设我有点(x,y,z),其中z = 0,并且在每个点我定义一个常数 函数f(x,y,z)=6。因此,如果我在isovalue 6上使用isosurface函数,我希望MATLAB给我一个3d绘图,XY平面以某种颜色突出显示,比如绿色。

2 个答案:

答案 0 :(得分:7)

我不太了解你的例子,但是这里是你使用isosurface绘制球体的方式:

%# create coordinates
[xx,yy,zz] = meshgrid(-15:15,-15:15,-15:15);
%# calculate distance from center of the cube
rr = sqrt(xx.^2 + yy.^2 + zz.^2);

%# create the isosurface by thresholding at a iso-value of 10
isosurface(xx,yy,zz,rr,10);

%# make sure it will look like a sphere
axis equal 

enter image description here

答案 1 :(得分:3)

你给出的例子非常无趣,实际上甚至可能有问题。

通过将所有积分折叠到z=0,,您不再需要/需要使用ISOSURFACE,而应调用CONTOUR。即便如此,常量函数f(X,Y)=6也不会显示任何内容......

由于@Jonas已经展示了如何使用ISOSURFACE,以下是CONTOUR函数的一个示例:

%# create a function to apply to all X/Y coordinates
[X,Y] = meshgrid(-2:0.1:2,-1:0.1:1);
f = @(X,Y) X.^3 -2*Y.^2 -3*X;

%# plot the function surface
subplot(121), surfc(X,Y,f(X,Y))
axis equal, daspect([1 1 3])

%# plot the iso-contour corresponding to where f=-1
subplot(122), contour(X,Y,f(X,Y),[-1 -1]), 
axis square, title('Contour where f(X,Y)=-1')

enter image description here