Matlab简单教程:绘图

来源:互联网 发布:手机电台录音软件 编辑:程序博客网 时间:2024/06/06 12:34

绘制sin曲线

x = 0:pi/10:2*pi;y = sin(x);plot(x,y);

设置样式

  • 连续线、点线等
x = 0:pi/10:2*pi;y = sin(x);plot(x,y,'LineStyle','-.'); % 断点线

其它可选值:https://cn.mathworks.com/help/matlab/ref/plot.html?s_tid=gn_loc_drop#input_argument_namevalue_d119e766669

  • 线的粗细
x = 0:pi/10:2*pi;y = sin(x);plot(x,y,'LineWidth',2);  %线宽为2,默认为0.5

其它可选值:https://cn.mathworks.com/help/matlab/ref/plot.html?s_tid=gn_loc_drop#input_argument_namevalue_d119e766777

  • 线的颜色
x = 0:pi/10:2*pi;y = sin(x);plot(x,y,'Color','r');   %红色线

其它可选值:https://cn.mathworks.com/help/matlab/ref/plot.html?s_tid=gn_loc_drop#input_argument_namevalue_d119e766499

  • 数据点样式
x = 0:pi/10:2*pi;y = sin(x);plot(x,y,'Marker','s');   %方块点

其它可选值:https://cn.mathworks.com/help/matlab/ref/plot.html?s_tid=gn_loc_drop#input_argument_namevalue_d119e766805

设置标题、xlabel、ylabel

x = 0:pi/10:2*pi;y = sin(x);plot(x,y);title('sin demo');xlabel('x axis');ylabel('y axis');

在一张图上绘制多条曲线

绘制两条曲线

x = 0:pi/10:2*pi;y1 = sin(x);y2 = cos(x);figureplot(x,y1);hold onplot(x,y2)legend('sin','cos')hold off

一次绘制一个点

x = 0:pi/10:2*pi;y = sin(x);figurefor i=1:length(x)    plot(x(i),y(i),'Marker', 's')    hold onendhold off

subplot

x = 0:pi/10:2*pi;y1 = sin(x);y2 = cos(y);y3 = x;y4 = x.^2;y5 = 1./(x+1);y6 = exp(x);figuresubplot(2,3,1) %2x3=6张图,编号从1到6,从上到下,从左到右plot(x,y1)subplot(2,3,2)plot(x,y2)subplot(2,3,3)plot(x,y3)subplot(2,3,4)plot(x,y4)subplot(2,3,5)plot(x,y5)subplot(2,3,6)plot(x,y6)

原创粉丝点击