MATLAB三维图像绘制技巧‌

%% 基本操作 plot3(x1,y1,z1,'options1',x2,y2,z2,'options2',...)多条线 x = 1:0.1:10; y = 1:0.1:10; z = x.^2+y; plot3(x,y,z,'r--') grid on %% 参数方程 t = 0:pi/50:10*pi; y1 = sin(t); y2 = cos(t); plot3(y1,y2,t,'b-'); grid on %% meshgrid是MATLAB中用于生成网格采样点的函数 向量转化为矩阵 %[X,Y]=meshgrid指令的作用是: % 1、生成以向量x为行,向量y为列的矩阵, % 2、并且向量x的长度为新矩阵的列数,y的长度为新矩阵的行数 的新矩阵X和Y % 向量x=[1,2,3],向量y=[4,5] %X= %  1 2 3 %  1 2 3 %Y= %  4 4 4 %  5 5 5 %[X Y]= %  1 2 3 4 4 4 %  1 2 3 5 5 5 x = -3:0.2:3; y = 1:0.2:5; [X,Y]=meshgrid(x,y); Z = (X+Y).^2; subplot(2,2,1) plot3(X,Y,Z) subplot(2,2,2) plot3(X,Y,Z) x = -3:0.1:3; y = 1:0.1:5; [X,Y]=meshgrid(x,y); Z = (X+Y).^2; subplot(2,2,3) plot3(X,Y,Z) subplot(2,2,4) plot3(X,Y,Z) %% 空间曲面 surf绘制得到的是着色的三维曲面(黑色线,彩色面) % shading faceted:默认模式,在曲面或图形对象上叠加黑色的网格线; % shading flat:是在shading faceted的基础上去掉图上的网格线; % shading interp:对曲面或图形对象的颜色着色进行色彩的插值处理,使色彩平滑过渡 ; x = -3:0.2:3; y = 1:0.2:5; [X,Y]=meshgrid(x,y); Z = (X+Y).^2; subplot(2,2,1) surf(X,Y,Z) subplot(2,2,2) surf(X,Y,Z) shading flat%与小图1有区别,相对于小图1去掉了网格线(曲面图里比较清晰) x = -3:0.1:3; y = 1:0.1:5; [X,Y]=meshgrid(x,y); Z = (X+Y).^2; subplot(2,2,3) surf(X,Y,Z) subplot(2,2,4) surf(X,Y,Z) shading flat%与小图3有区别,相对于小图3去掉了网格线(曲面图里比较清晰) %% mesh绘制的图形是一个一排排的彩色曲线组成的网格图(彩色线,白色面) x = -3:0.2:3; y = 1:0.2:5; [X,Y]=meshgrid(x,y); Z = (X+Y).^2; subplot(2,2,1) mesh(X,Y,Z) subplot(2,2,2) mesh(X,Y,Z) x = -3:0.1:3; y = 1:0.1:5; [X,Y]=meshgrid(x,y); Z = (X+Y).^2; subplot(2,2,3) mesh(X,Y,Z) subplot(2,2,4) mesh(X,Y,Z) %% 复杂的三维曲面(二合一) m = 30; z = 1.2*(0:m)/m; r = ones(size(z)); theta = (0:m)/m*2*pi; x1 = r'*cos(theta);y1=r'*sin(theta); z1 = z'*ones(1,m+1); x = (-m:2:m)/m; x2 = x'*ones(1,m+1);y2=r'*cos(theta); z2 = r'*sin(theta); surf(x1,y1,z1);           axis equal ,axis off %axis equal:纵横坐标轴采用等长刻度  axis off:关闭所有的坐标轴标签、刻度 hold on %保留第一个图像 surf(x2,y2,z2);           axis equal ,axis off title ('啦啦啦'); hold off %hold on 成对出现 %% meshc等高线的三维网格曲面 meshz带底座的三维网格曲面函数 surfc等高线的曲面函数 surfl具有光照效果的曲面函数 [x,y]=meshgrid(-8:0.5:8);% [A,B]=meshgrid(m) 等同于 [A,B]=meshgrid(m,m) z=sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2+eps);%sqrt 开根号 subplot(2,2,1); meshc(x,y,z); subplot(2,2,2); meshz(x,y,z); subplot(2,2,3); surfc(x,y,z); subplot(2,2,4); surfl(x,y,z); %% sphere三维球面 [x,y,z]=sphere(n);%n越大,越平滑 [x,y,z]=sphere(100); subplot(2,2,1) mesh(x,y,z) grid on axis equal subplot(2,2,2) mesh(3*x,y,3*z) axis equal grid on subplot(2,2,3) mesh(5*x,y,z) axis equal grid on subplot(2,2,4) mesh(x,6*y,z) axis equal grid on %%  cylinder柱面 [x,y,z]=cylinder(R,n)半径为r、高度为1、沿其周长有n个等距分布的点的圆柱体 [x,y,z]=cylinder(5,200); subplot(2,2,1) mesh(x,y,z) axis equal grid on subplot(2,2,2) surf(z,5*y,x) axis equal grid on subplot(2,2,3) mesh(x,5*y,5*z) axis equal grid on t = 0:0.1:pi; [x,y,z]=cylinder(sin(t),200); subplot(2,2,4) mesh(x,y,z) axis equal grid on %% 条形图 杆图 饼图 填充图 subplot(2,2,1); bar3(rand(4));%条形图 rand是生成随机数 subplot(2,2,2); y=2*sin(0:pi/10:2*pi); stem3(y);%杆图 subplot(2,2,3); pie3([2347,1827,2043,3025,5520]);%饼图 “中括号”里填写各个数值的大小 subplot(2,2,4); fill3(rand(3,5),rand(3,5),rand(3,5),'r');%填充图 %% waterfall绘制瀑布图 网格线在x轴方向出现 具有瀑布效果;contourZ 绘制矩阵Z的等高线 Z表示距X-Y平面的高度 x = 0:0.5:5*pi; y = 0:0.5:5*pi; [X Y] = meshgrid(x,y); Z = cos(X)+sin(Y); subplot(2,2,1) mesh(X,Y,Z) axis equal grid on subplot(2,2,2) surf(X,Y,Z) axis equal grid on subplot(2,2,3) % contour(X,Y,Z,20,'b')%等高线图 二维 contour3(X,Y,Z, 5,'b','ShowText','on')%等高线图 三维 (X,Y,Z,等高线数目 默认为7个线条) % contour3(X,Y,Z, [-0.5 0.5],'b','ShowText','on')%等高线图 三维 (X,Y,Z,显示区间) axis equal grid on subplot(2,2,4) waterfall(X,Y,Z)%瀑布图 axis equal grid on %% view(a,e) 其中a为方位角(视点在xy平面上的投影与y轴负方向的夹角)e为仰角(视点与原点连线,和xy平面的夹角) subplot(2,2,1);mesh(peaks);%peaks:二元高斯分布的概率密度函数 view(-37.5,30);%系统默认的方位角和仰角 xlabel('$x$','interpreter','latex') ylabel('$y$','interpreter','latex','rotation',360) title('1'); subplot(2,2,2);mesh(peaks); view(0,90); xlabel('$x$','interpreter','latex') ylabel('$y$','interpreter','latex','rotation',360) title('2'); subplot(2,2,3);mesh(peaks); view(90,0); xlabel('$x$','interpreter','latex') ylabel('$y$','interpreter','latex','rotation',360) title('3'); subplot(2,2,4);mesh(peaks); view(-7,-10); xlabel('$x$','interpreter','latex') ylabel('$y$','interpreter','latex','rotation',360) title('4'); %% NaN的运用 x=0:pi/50:4*pi; y=sin(x); i=find(abs(y)>0.5);%find函数查找向量中的非零元素的位置 abs函数返回数组X中每个元素的绝对值 x(i)=NaN;%NaN常数可以用于表示那些不可使用的数据;NaN的部分将不显示出来 figure(1) plot(x,y,'bo'); hold on x1 = 0:pi/50:4*pi; y1 = sin(x1); plot(x1,y1,'r-') hold off %% 动图 pause(n) %n为延迟的秒数 for i=0:0.1:2*pi     pause(0.01) %每个点停留0.01秒     hold on     plot(i,sin(i),'ro')     hold on     plot(2*pi-i,cos(i),'b*') end

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空