【参考教学视频:https://www.bilibili.com/video/av14503445/?p=5】
目录
plot()
matlab 在画图是会将前面的图覆盖掉,除非用hold on 和 hold off
(通过hold on 可以将多条线画在同一个图形之中)
plot指定 形状:
如:
(1)
hold on;
plot(cos(0:pi/20:2*pi),'or--');
plot(sin(0:pi/20:2*pi),'xg:');
hold off;
(2)
x = 0:0.5:4*pi;
y = sin(x);
h = cos(x);
w = 1./(1+exp(-x));
g = (1/(2*pi*2)^0.5).*exp((-1.*(x-2*pi).^2)./(2*2^2));
plot(x,y,'bd-',x,h,'gp:',x,w,'ro-',x,g,'c^-');
(3)
plot(x, y1,'--*',x,y2,':o');
xlabel('t = 0 to 2\pi');
ylabel('values of sin(t) and e^{x}');
title('Function Plots of sin(t) and e^{x}');
legend('sin(t)','e^{x}');
text() 、annotation():
例如:
clc ;
clear;
x = linspace(0,3);
y = x.^2.*sin(x);
plot(x,y);
line([2,2],[0,2^2*sin(2)]);
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';
text(0.25,2.5,str,'Interpreter','latex');
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]);
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';
text(0.25,2.5,str,'Interpreter','latex');
——>积分公式的显示
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]); ——>箭头。
【练习】
clc ;
clear;
x = 1:0.02:2;
y1 = x.^2;
y2 = sin(2*pi.*x);
plot(x,y1,'-k',x,y2,'or');
ylabel('f(t)');
xlabel('Time(ms)');
title('Mini Assignment #1');
legend('{t}^2','sin(2\pi{t})');
更改图像的性质:
如: