在Matlab中如何将三维数组绘制成三维曲面

来源:百度知道 编辑:UC知道 时间:2024/05/28 12:27:11
比如一个矩阵A(11,11,21),我想画出三维曲面,第一个坐标为x轴,第二个坐标为y轴,第三个坐标为z轴,该怎么画呢?多谢指教

编写mymesh()函数:
function mymesh()
temdat=load('D:\test.txt');
if temdat== -1
('Error opening the file');
end
figure;
h=plot3(temdat(:,1),temdat(:,2),temdat(:,3));
set(h,'linestyle','none')
hold on;
grid on;
[x,y]=meshgrid(linspace(-150,150,500),linspace(-150,150,500));
z = griddata(temdat(:,1),temdat(:,2),temdat(:,4),x,y);
meshc(x,y,z);
axis([0,180,0,180]);

坐标放在D:\test.txt里(你也可以改成其他的),格式如下:
45 32 56
78 45 21
46 79 55
46 75 22
14 69 75
……

A是个多行3列的矩阵的话,试试这样。
x=A(:,1);
y=A(:,2);
z=A(:,3);
plot3(x,y,z);

[xx,yy]=meshgrid(x,y)
mesh(xx,yy,z)