目录
1、绘制三维曲线图
plot3为三维绘图的基本函数,格式为:
plot3(x,y,z,LineSpec,...),x,y,z为向量,LineSpec为定义曲线线型。
x=[1 2 3 4 5];
y=[1 2 3 4 5];
z=[1 2 3 4 5];
plot3(x,y,z)
grid
2、绘制三维网格图
mesh为三维网格图绘制函数,格式为: mesh(x,y,z)。另外还有meshc:用来绘制等值线网格图,meshz:用来绘制包含0平面的网格图。
[x,y,z]=peaks(50);
subplot(131);mesh(x,y,z)
subplot(132);meshc(x,y,z)
subplot(133);meshz(x,y,z)
另外命令hidden off使网格图不透明显示,如下:
[x,y,z]=sphere(15);%球
subplot(121);
mesh(x,y,z)
title('不透明球');
hidden off
subplot(122);
mesh(x,y,z)
title('透明球');
3、 绘制三维曲面图
surf绘制着色的三维曲面图,格式为:surf(x,y,z)。另外有surfc:绘制了底层等高线图,surfl:考虑了有光照效果的表面图。
函数shading flat:平面阴影,shading interp:插值阴影。
[x,y,z]=peaks(18);
subplot(131);surf(x,y,z),title('surf');
subplot(132);surfc(x,y,z),title('surfc');
subplot(133);surfl(x,y,z),title('surfl');
4、特殊图形绘制
(1)绘制圆柱型
格式为:[x,y,z]=cylinder,[x,y,z]=cylinder(r),[x,y,z]=cylinder(r,n),对于这三个函数来说高度都为1,地面半径分别为:1,r,r,距离相同的点有20,20,n。
cylinder(2)
(2) 绘制球型
格式为:sphere(n)。
sphere(30)
(3) 绘制三维离散数据
格式为:stem3(x,y,z,c,'filled'),其中c代表线条颜色,filled填充点。
x=rand(3);
stem3(x,'bo','filled')
(4)等高线和带状图
二维等高线图:contour(),三维等高线图:contour3(),带状图:ribbon(x,y)。
[x,y,z]=peaks(15);
m=peaks(20);
subplot(131);contour(x,y,z,20)
subplot(132);contour3(x,y,z,20)
subplot(133);ribbon(m)
5、立体可视化
(1)视觉化作图
x=0:0.2:5;
y=1:0.3:6;
z=3:0.25:8;
[x1,y1,z1]=meshgrid(x,y,z);
v=x1+y1+z1;
slice(x1,y1,z1,v,[4.2],[3],[5.25])
xlabel('x-axis');ylabel('y-axis');zlabel('z-axis');
(2)四维表现图
x=0:0.2:5;
y=1:0.3:6;
z=3:0.25:8;
[x1,y1,z1]=meshgrid(x,y,z);
v=x1+y1+z1;
xslice=[3,4,5];yslice=[4];zslice=[3,5];
slice(x1,y1,z1,v,xslice,yslice,zslice)
colormap hsv %colormap是MATLAB里面用来设定和获取当前色图的函数。
xlabel('x-axis');ylabel('y-axis');zlabel('z-axis');
6、视角控制
用于视角控制的函数为:view,viewmtx,rotate3d。
[x,y,z]=peaks(20);
subplot(221);surf(x,y,z),title('默认视角');
subplot(222);surf(x,y,z),view(0,90),title('view(0,90)');
subplot(223);surf(x,y,z),view(-60,60),title('view(-60,60)');
subplot(224);surf(x,y,z),view(30,78),title('view(30,78)');