1.条形图(Bar Plot)
t = -10:1:10;
subplot(2,2,1);
bar(t, cos(t));
复制代码
这里创建了一个包含元素从-10到10的向量 t。在第一个子图中,使用 bar 函数绘制了 cos(t) 的条形图。bar 函数的第一个参数是 x 轴坐标,第二个参数是对应于每个 x 坐标的高度或值。这个子图显示了 cos(t) 在给定范围内的变化。
极坐标图(Compass Plot)
subplot(2,2,2);
compass(t, cos(t));
复制代码
在第二个子图中,使用 compass 函数创建了一个极坐标图。compass 函数以 t 为输入,cos(t) 作为极坐标的幅度。这个图形显示了 cos(t) 的相位和幅度信息。
玫瑰图(Rose Plot)
subplot(2,2,3);
rose(t, cos(t));
复制代码
第三个子图使用 rose 函数创建了一个玫瑰图。rose 函数接受角度向量 t 和对应的值 cos(t),然后绘制出与极坐标轴上的角度对应的频率。这个图形以玫瑰花瓣的形式展示了 cos(t) 的分布。
填充图(Filled Plot)
subplot(2,2,4);
fill(t, cos(t), 'b');
复制代码
在第四个子图中,使用 fill 函数创建了一个填充图。fill 函数的第一个参数是 x 轴坐标,第二个参数是对应于每个 x 坐标的 y 值。此外,'b' 表示使用蓝色填充。这个图形显示了 cos(t) 在给定范围内的填充效果。
结果截图图下:
2.1.clear: 清除 MATLAB 工作空间中的所有变量。
2.clc: 清除 MATLAB 命令窗口的内容。
然后,在生成时间向量 t 后,两个信号 y 和 Y 分别表示为 sin(t) 和 sin(10*t)。接着,对这两个信号进行对应元素相乘,得到新的信号 c。
最后,使用 plot 函数在同一张图上绘制了原始信号 y(用红色虚线表示)和相乘后的信号 c(用蓝色实线表示)。这样的图形可以用来展示信号的相乘效果。
clear
clc
t=0:0.001:10;
y=sin(t);
% plot(t,y);
Y=sin(10*t);
c=y.*Y;
plot(t,y,'r:',t,c,'b')
复制代码
3.1.clear: 清除 MATLAB 工作空间中的所有变量。
2.clc: 清除 MATLAB 命令窗口的内容。
然后,定义了一个包含四个数据元素的向量 x。接着,创建了一个与 x 相同大小的零向量 explode,用于设置哪一块需要突出显示。
通过 min 函数找到向量 x 中的最小值 c 和对应的索引 offset。然后,将 explode 中最小值对应的位置设置为最小值 c。
最后,使用 pie 函数创建一个饼图,其中通过 explode 参数实现了突出显示最小值的效果。饼图的每个扇区的大小由向量 x 中的元素决定。
clear
clc
x=[11.4 23.5 35.4 15.6];
explode=zeros(size(x));
[c,offset]=min(x);
explode(offset)=c;
pie(x,explode)
复制代码
4.1.clear: 清除 MATLAB 工作空间中的所有变量。
2.clc: 清除 MATLAB 命令窗口的内容。
然后,通过 meshgrid 函数生成了一个二维网格,其中 x 和 y 都是 401x401 的矩阵,表示在二维空间的坐标。
接下来,计算了每个点到中心的距离 r,并计算了二维 sinc 函数的值 z。
最后,使用 subplot 函数创建一个包含两个子图的图形窗口。在第一个子图中,使用 mesh 函数绘制了二维 sinc 函数的三维网格图。在第二个子图中,使用 surf 函数绘制了 sinc 函数的曲面图。这样可以同时比较二维网格图和曲面图的表示方式。
clear
clc
x=-2:0.01:2;
[x,y]=meshgrid(x,x); %x和y都是401x401的矩阵
r=sqrt(x.^2+x.^2)+eps;
z=sinc(r);
subplot(2,1,1);
mesh(z);
subplot(2,1,2);
surf(x,y,z);
复制代码
5.
使用 peaks 函数生成一个典型的山峰状三维曲面,并通过不同的图形绘制函数在子图中展示了多个视图和效果。
meshz 函数(第一个子图):绘制曲面并加上围裙,即显示曲面和零平面。
waterfall 函数(第二个子图):在 x 方向产生水流效果的曲面图。
meshc 函数(第三个子图):同时画出网状图和等高线。
surfc 函数(第四个子图):同时画出曲面图和等高线。
surfl 函数(第五个子图):给出带光照效果的彩色表面图。
contourf 函数(第六个子图):绘制等高线填充图,即带有颜色填充的等高线图。
每个子图都使用 axis([-inf inf -inf inf -inf inf]) 来设置坐标轴的显示范围。
clear
clc
[x,y,z] =peaks;
subplot(2,3,1);
meshz(x,y,z); %曲面加上围裙,即给出曲面和零平面
axis([-inf inf -inf inf -inf inf]);
subplot(2,3,2);
waterfall(x,y,z); %在x方向产生水流效果
axis([-inf inf -inf inf -inf inf]);
subplot(2,3,3);
meshc(x,y,z); %同时画出网状图与等高线
axis([-inf inf -inf inf -inf inf]);
subplot(2,3,4);
surfc(x,y,z); %同时画出曲面图与等高线
axis([-inf inf -inf inf -inf inf]);
subplot(2,3,5)
surfl(x,y,z); %给出带光照效果的彩色表面图
axis([-inf inf -inf inf -inf inf]);
subplot(2,3,6)
contourf(x,y,z);
axis([-inf inf -inf inf -inf inf]);
复制代码
6.
clear
clc
[X0,Y0,Z0]=sphere(30); %产生单位球面的三维坐标
X=2*X0;Y=2*Y0;Z=2*Z0; %产生半径为2的球面的三维坐标
clf
subplot(1,2,1);
surf(X0,Y0,Z0); %画单位球面
shading interp %采用插补明暗处理
hold on,mesh(X,Y,Z),colormap(hot),hold off %采用hot色图
hidden off %产生透视效果
axis equal,axis off %不显示坐标轴
title('透视图')
subplot(1,2,2);
surf(X0,Y0,Z0); %画单位球面
shading interp %采用插补明暗处理
hold on,mesh(X,Y,Z),colormap(hot),hold off %采用hot色图
hidden on %产生消隐效果
axis equal,axis off %不显示坐标轴
title('消隐图')
复制代码
7.
clear
clc
subplot(2,2,1), fplot(@humps, [0 1])
subplot(2,2,2), fplot(@(x) abs(exp(-1i*x*(0:9))*ones(10,1)), [0 2*pi])
% % Vectorize the function for subplot(2,2,3)
% vec_func = @(x) [tan(x),sin(x),cos(x)];
% x_range = linspace(2*pi*(-1), 2*pi*(1), 1000); % Adjust the number of points as needed
% subplot(2,2,3), fplot(vec_func, x_range)
subplot(2,2,4), fplot(@(x) sin(1 ./ x), [0.01 0.1], 1e-3)
复制代码
8.
clear
clc
subplot(3,3,1)
ezplot('cos(x)')
subplot(3,3,2)
ezplot('cos(x)', [0, pi])
subplot(3,3,3)
ezplot('1/y-log(y)+log(-1+y)+x - 1')
subplot(3,3,4)
ezplot('x^2 - y^2 - 1')
subplot(3,3,5)
ezplot('x^2 + y^2 - 1',[-1.25,1.25]);
axis equal
subplot(3,3,6)
ezplot('x^3 + y^3 - 5*x*y + 1/5',[-3,3])
subplot(3,3,7)
ezplot('x^3 + 2*x^2 - 3*x + 5 - y^2')
subplot(3,3,8)
复制代码
9.
clear
clc
t=(0:0.02:2)*pi;
x=sin(t);
y=cos(t);
z=cos(2*t);
plot3(x,y,z,'b-',x,y,z,'bd')
view([-82,58]);
box on
legend('链','宝石');
复制代码
10。
clear
clc
subplot(2,2,1)
contour3(peaks,50); %画出曲面在三度空间中的等高线
axis([-inf inf -inf inf -inf inf]);
subplot(2,2,2)
contour(peaks, 50); %画出曲面等高线在XY平面的投影
subplot(2,2,3)
t=linspace(0,20*pi, 501);
plot3(t.*sin(t), t.*cos(t), t);% 画出三度空间中的曲线
subplot(2,2,4)
plot3(t.*sin(t), t.*cos(t), t, t.*sin(t), t.*cos(t), -t);% 同时画出两条三度空间中的曲线<i< p=""></i<>
复制代码
11.
clear
clc
subplot(1,2,1);
t = 0:0.01:2*pi;
x = cos(2*t).*(cos(t).^2);
y = sin(2*t).*(sin(t).^2);
comet(x,y)
subplot(1,2,2);
t = -10*pi:pi/250:10*pi;
comet3((cos(2*t).^2).*sin(t),(sin(2*t).^2).*cos(t),t)
复制代码
网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。