1.基础绘图
和python类似
1.1 绘图:plot()
如果绘制多条曲线,需要使用hold on-hold off ,不然后面的曲线会覆盖掉前面的。
hold on
plot(cos(0:pi/20:2*pi),'o-k');
plot(sin(0:pi/20:2*pi),'X--b');
hold off%两个一起画;不使用hold on的话,默认会覆盖掉前面那张图片
1.2 样式
plot样式
plot(x,y,‘str’)
图例:legend()
title()和xlabel()ylabel()zlabel()
x=0:0.5:4*pi;
y=sin(x);
h=cos(x);
w=1./(1+exp(-x));
xlabel('t=0 tp 2\pi');
ylabel('values of sin(t) and e^{-x}');
plot(x,y,'bd-',x,h,'gp:',x,w,'ro-',x,w,'c^-');%样式
title('values of sin(t) and e^{-x}');%标题
legend('sin(x)','cos(x)','sigmoid','Gauss function');%图例
text() and annotation()
数学公式使用latex
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 $$';%表示积分函数