最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

MATLAB三维绘图

来源:动视网 责编:小OO 时间:2025-10-02 10:57:59
文档

MATLAB三维绘图

MATLAB三维绘图一、基本三维绘图基本绘图步骤:%数据准备:x=-8:0.1:8;y=-8:0.1:8;[X,Y]=meshgrid(x,y);Z=(exp(X)-exp(Y)).*sin(X-Y);%图形窗口和绘图区选择:figure%绘图:surf(X,Y,Z)%设置视角:view([7525])%设置颜色表:colormaphsvshadinginterp%设置光照效果:light(‘Position’,[10.50.5])lightinggouraudmaterialmetal%设置
推荐度:
导读MATLAB三维绘图一、基本三维绘图基本绘图步骤:%数据准备:x=-8:0.1:8;y=-8:0.1:8;[X,Y]=meshgrid(x,y);Z=(exp(X)-exp(Y)).*sin(X-Y);%图形窗口和绘图区选择:figure%绘图:surf(X,Y,Z)%设置视角:view([7525])%设置颜色表:colormaphsvshadinginterp%设置光照效果:light(‘Position’,[10.50.5])lightinggouraudmaterialmetal%设置
MATLAB 三维绘图

一、基本三维绘图

基本绘图步骤:

%数据准备:

x=-8:0.1:8;

y=-8:0.1:8;

[X,Y]=meshgrid(x,y);

Z=(exp(X)-exp(Y)).*sin(X-Y);

%图形窗口和绘图区选择:

figure

%绘图:

surf(X,Y,Z)

%设置视角:

view([75 25])

%设置颜色表:

colormap hsv

shading interp

%设置光照效果:

light(‘Position’,[1 0.5 0.5])

lighting gouraud

material metal

%设置坐标轴刻度和比例:

axis square

set(gca,’ZTickLabel’)

%标注图形:

Xlabel(‘x’)

Ylabel(‘y’)

colorbar

1.三维曲线图

例:三维曲线图

close all

x=-5:0.4:5;

y=5:-0.4:-5;

z=exp(-0.2*x).*cos(y);

figure

subplot(2,1,1);

plot3(x,y,z,’or’,x,y,z)

[X,Y]=meshgrid(x,y);

Z= exp(-0.2*X).*cos(Y);

subplot(2,1,2);

plot3(X,Y,Z)

2.三维曲面图

(1)矩形网络

例:矩形网络

x=-5:0.4:5;

y=5:-0.4:-5;

[X,Y]=meshgrid(x,y);

subplot(2,1,1);

plot(x,y,’o’)

subplot(2,1,2)

plot(X,Y,’o’)

(2)三维网线图

例:三维网线图

close all

clear

[X,Y]=meshgrid(-3:0.5:3);

Z=2*X.^2-3*Y.^2;

subplot(2,2,1);plot3(X,Y,Z);title(‘plot3’)

subplot(2,2,2);mesh(X,Y,Z);title(‘mesh’)

subplot(2,2,3);meshc(X,Y,Z);title(‘meshc’)

subplot(2,2,4);meshz(X,Y,Z);title(‘meshz’)

(3)三维表面图

例:三维表面图

close all

clear

[X,Y]=meshgrid(-3:0.5:3);

Z=2*X.^2-3*Y.^2;

subplot(2,2,1);mesh(X,Y,Z);title(‘mesh’)

subplot(2,2,2);surf(X,Y,Z);title(‘surf)

subplot(2,2,3);surfc(X,Y,Z);title(‘surfc’)

subplot(2,2,4);surfl(X,Y,Z);title(‘surfl’)

(4) 网格边框线设置

例:网格边框线设置

close all

clear

[X,Y]=meshgrid(-3:0.25:3);

Z=-sqrt(X..^2+3*Y.^2);

subplot(2,2,1);mesh(X,Y,Z); hidden on ; title(‘hidden on’)

subplot(2,2,2);mesh(X,Y,Z); hidden off; title(‘hidden off)

二、特殊绘图函数

1.柱状图

例:三维柱状图

clear

x=rand(3,10);

subplot(2,2,1);bar(x);title(‘bar’)

subplot(2,2,2);barh(x,’stack’);title(‘barh stack’)

subplot(2,2,3);bar3(x);title(‘bar’)

subplot(2,2,4);bar3h(x,’stack’);title(‘‘bar3h stack’’)

2.散点图

例:三维散点图

close all

clear

x=rand(1,10);

y=rand(1,10);

z=x.^2+y.^2;

scatter3(x,y,z,’ro’)

hold on

[X,Y]=meshgrid(0:0.1:1);

Z=X.^2+Y.^2;

mesh(X,Y,Z)

hidden off

3.饼状图

例:三维饼状图

x=[32 45 11 76 56];

explode=[0 0 1 0 1];

pie3(x,explode)

4.火柴杆图

例:三维火柴杆图

clear

x=rand(1,10);

y=rand(1,10);

z=x.^2+2*y;

stem3(x,y,z,’fill’)

5.向量场图

例:三维向量场图

clear

close all

[X,Y]=meshgrid(-3:0.4:3);

Z=-3*X.^2-Y.^2;

[U,V,W]=surfnorm(X,Y,Z);

quiver3(X,Y,Z,U,V,W,0.2)

hold on

surf(X,Y,Z)

6.等值线图

例:三维等值线图

clear

close all

[X,Y]=meshgrid(-3:0.01:3);

Z=X.^2+Y.^2;

contour3(X,Y,Z,20)

view([45 50])

7.简易绘图函数

例:简易三维绘图函数

close all

clear

subplot(2,2,1); ezplot(‘sin(t)’,’cos(t)’,’sin(2*t)’,[0,2*pi])

subplot(2,2,2);ezmesh(@peaks, [-5 5 -5 5])

subplot(2,2,3);ezsurf(@(x,y)(x.^2+y.^2), [-5 5 -5 5])

subplot(2,2,4);ezsurfc(@(x,y)( x.^2+y.^2), [-5 5 -5 5])

三、三维图形显示控制

1.设置坐标轴

例:设置坐标轴

close all

subplot(1,3,1)

ezsurf(@(t,s)(sin(t).*cos(s)), @(t,s)(sin(t).*sin(s)), @(t,s)(cos(t)), [0,2*pi,0,2*pi] )

axis auto; title(‘auto’)

subplot(1,3,2)

ezsurf(@(t,s)(sin(t).*cos(s)), @(t,s)(sin(t).*sin(s)), @(t,s)(cos(t)), [0,2*pi,0,2*pi] )

axis equal; title(‘equal’)

subplot(1,3,3)

ezsurf(@(t,s)(sin(t).*cos(s)), @(t,s)(sin(t).*sin(s)), @(t,s)(cos(t)), [0,2*pi,0,2*pi] )

axis square; title(‘square’)

2.设置视角

例:设置视角

clear

close all

subplot(2,2,1)

ezmesh(@peaks);

view(3);

[a,b]=view;title(mat2str([a,b]))

subplot(2,2,2)

ezmesh(@peaks);

view(2);

[a,b]=view;title(mat2str([a,b]))

subplot(2,2,3)

ezmesh(@peaks);

view([30 45]);

[a,b]=view;title(mat2str([a,b]))

subplot(2,2,4)

ezmesh(@peaks);

view([1 1 sqrt(2)]);

[a,b]=view;title(mat2str([a,b]))

文档

MATLAB三维绘图

MATLAB三维绘图一、基本三维绘图基本绘图步骤:%数据准备:x=-8:0.1:8;y=-8:0.1:8;[X,Y]=meshgrid(x,y);Z=(exp(X)-exp(Y)).*sin(X-Y);%图形窗口和绘图区选择:figure%绘图:surf(X,Y,Z)%设置视角:view([7525])%设置颜色表:colormaphsvshadinginterp%设置光照效果:light(‘Position’,[10.50.5])lightinggouraudmaterialmetal%设置
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top