基础绘图

plot from “Data”

plot()

  • plot(x,y) 画每一个对应的点x、y
  • plot(y) 画每一个点(x, y) 其中x=[1,2,3…, n], n = length(y)
  • 例: plot(cos(0:pi/20:2*pi)); 画的是y为一连串cos值,x为0、1、2、…

hold on/off

plot画图会有服盖效果,先画cos 再画sin 那么看到的是sin 而不是sin和cos的重叠

如果不想matlab每次画图都刷新画板,使用hold on

结束画图后使用hold off

例如:

1
2
3
4
hold on
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));
hold off

plot style

  • plot(x, y, ‘str’); xy后面的参数指定画出来图形的风格

1

例如:

1
2
3
4
hold on
plot(cos(0:pi/20:2*pi),'or');
plot(sin(0:pi/20:2*pi),'xg');
hold off
  • cos画的是红色圈圈
  • sin画的是绿色叉叉

legend()

  • 用于给图添加注解
  • legend(‘L1’,’L2’…) L1对应为画的第一条线

1

1

title and ?label()

  • title(‘…’)
  • xlabel(‘…’)
  • ylabel(‘…’)
  • zlabel(‘…’)

text() and annotation()

  • Text里面要表示数学公式要使用LaTex标准

1

1

Donate? comment?