【MATLAB】MATLAB 可视化之曲面图与网格图

翻译自 MATLAB 官方文档

surf : 曲面图

[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
C = X.*Y;
surf(X,Y,Z,C)
colorbar

x

surfc : 带等高线的曲面图

[X,Y,Z] = peaks(30);
figure
surfc(X,Y,Z)

x

surface:创建曲面对象

surface 是一个创建曲面图形对象的低级函数。曲面是将每个元素的行和列索引用作 x 和 y 坐标、将每个元素的值用作 z 坐标而创建的矩阵数据图。

[XD,YD,ZD] = peaks(25);


load clown
C = flipud(X);

figure
surface(XD,YD,ZD,C,...
    'FaceColor','texturemap',...
    'EdgeColor','none',...
    'CDataMapping','direct')
colormap(map)
view(-35,45)

xx

surfl : 具有基于颜色图的光照的曲面图

surfl 函数基于环境光、漫反射和镜面反射光照模型显示阴影曲面。

[x,y] = meshgrid(-3:1/8:3);
z = peaks(x,y);
surfl(x,y,z)
shading interp

使用基于颜色图的光照创建 peaks 函数的曲面图。将 shading 设置为 interp 以在各线条和面间插入颜色。

x

surfnorm : 计算并显示三维曲面法向向量

[x,y,z] = cylinder(1:10);
figure
surfnorm(x,y,z)
axis([-12 12 -12 12 -0.1 1])

x

mesh : 网格图

 [X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
C = gradient(Z);

figure
mesh(X,Y,Z,C)

x

meshc : 带等高线的网格图

figure
[X,Y] = meshgrid(-3:.125:3);
Z = peaks(X,Y);
meshc(Z)

x

meshz : 围绕网格图绘制帷幕

figure
[X,Y] = meshgrid(-3:.125:3);
Z = peaks(X,Y);
meshz(Z)

x

hidden:显示网格图中被遮挡的隐线

figure
mesh(peaks)

hidden off

x

fsurf:解析方程绘制三维曲面

绘制分段表达式函数

erf(x)+cos(y)5<x<0,5<y<5sin(x)+cos(y)0<x<5,5<y<5 e r f ( x ) + c o s ( y ) − 5 < x < 0 , − 5 < y < 5 s i n ( x ) + c o s ( y ) 0 < x < 5 , − 5 < y < 5

f1 = @(x,y) erf(x)+cos(y);
fsurf(f1,[-5 0 -5 5])
hold on
f2 = @(x,y) sin(x)+cos(y);
fsurf(f2,[0 5 -5 5])
hold off

x

fmesh:解析方程绘制三维网格图

fmesh(@(x,y) erf(x)+cos(y),[-5 0 -5 5])
hold on
fmesh(@(x,y) sin(x)+cos(y),[0 5 -5 5])
hold off

fimplicit : 绘制三维隐函数

f = @(x,y,z) x.^2 + y.^2 - z.^2;
fimplicit3(f)

x

waterfall : 瀑布图

figure
[X,Y,Z] = peaks(30);
waterfall(X,Y,Z)

x

ribbon : 条带图

[x,y] = meshgrid(-3:.5:3,-3:.1:3);
z = peaks(x,y);

figure
ribbon(y,z)

x

contour3 : 3D 等高线图

x = -2:0.25:2;
[X,Y] = meshgrid(x);
Z = X.*exp(-X.^2-Y.^2);
contour3(X,Y,Z,30)

x

peaks: 包含两个变量的示例函数

peaks 是从高斯分布转换和缩放得来的包含两个变量的函数

figure
peaks(5);

x

cylinder : 生成圆柱面

生成剖面函数 2+sin(t) 2 + sin ⁡ ( t ) 定义的圆柱

t = 0:pi/10:2*pi;
figure
[X,Y,Z] = cylinder(2+cos(t));
surf(X,Y,Z)
axis square

图中的圆柱是将x-y 坐标轴的函数作为剖面曲线,将此曲线绕 x 轴旋转至与 z 轴对齐,然后绕 z 轴旋转一周,形成圆柱曲面

x

ellipsoid : 生成椭球面

[x, y, z] = ellipsoid(0,0,0,5.9,3.25,3.25,30);
figure
surf(x, y, z)
axis equal

x

sphere: 生成球面

[x,y,z] = sphere;

figure
surf(x,y,z)

hold on 
surf(x+3,y-2,z) % centered at (3,-2,0) 
surf(x,y+1,z-3) % centered at (0,1,-3)

x

[pcolor : 伪彩图/棋盘图]

pcolor(hadamard(20))
colormap(gray(2))
axis ij
axis square

x

  • 36
    点赞
  • 230
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值