freeyouth

整理自台大生机系郭彦甫.MATLAB系列教程,吐血推荐看这个视频,非计算机专业也能看懂,全程干货

 

MATLAB图形来自于“数据”,MATLAB不能理解函数。

MATLAB绘图原理:

   1.在特定范围生成函数的数值

   2.以图形的形式显示数据点

一、plot():

       绘制每个向量对

    绘制每个向量对,默认为x=[1,....,n]

       例1:

  plot(cos(0:pi/20:2*pi)); 

二、hold on/off:

   使用hold可以把两幅图放到一起

   例2

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

 

 

三、绘图风格:

使用一个字符串定义绘制风格。如“*--k”   数据点为星形,线为虚线,线颜色为黑色

例3:

       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^-\'); 

 

 

四、legend()

   添加图例:legend(\'L1\',...)

   例4:

legend(\'sin(x)\',\'cos(x)\',\'Sigmoid\',\'Gauss function\');

 

 

五、title() and label()

   title():添加标题

   xlabel():添加x轴标签

   ylabel():添加y轴标签

   zlabel():添加z轴标签

   例5:

      x = 0:0.1:2*pi; y1 = sin(x);

     plot(x, y1, \'--*\');

     xlabel(\'t = 0 to 2\pi\');

     ylabel(\'values of sin(t)\')

     title(\'Function Plots of sin(t)\');

     legend(\'sin(t)\');

 

六、subplot()

    把一个“图形”分成几小块

    subplot(m,n,1)

 

 

 

    例6

           t = 0:0.1:2*pi; x = 3*cos(t); y = sin(t);

        subplot(2, 2, 1); plot(x, y);

        subplot(2, 2, 2); plot(x, y,\'--\');

        subplot(2, 2, 3); plot(x, y,\':\');

        subplot(2, 2, 4); plot(x, y,\'*\');

 

七、将图形保存到文件中

    saveas(gcf,\'<filename>\',\'<formattype>\');

 

 

分类:

技术点:

相关文章:

  • 2021-09-13
  • 2021-12-07
  • 2021-10-27
  • 2021-11-07
  • 2021-07-02
  • 2021-10-30
  • 2021-10-21
猜你喜欢
  • 2021-08-01
  • 2021-12-18
  • 2019-12-06
  • 2021-07-14
  • 2021-11-23
  • 2021-09-30
  • 2022-12-23
相关资源
相似解决方案