MATBLAB學習筆記----基礎繪圖

整理自臺大生機系郭彥甫.MATLAB系列教程,吐血推薦看這個視頻,非計算機專業也能看懂,全程乾貨函數

 

MATLAB圖形來自於「數據」,MATLAB不能理解函數。code

MATLAB繪圖原理:orm

   1.在特定範圍生成函數的數值視頻

   2.以圖形的形式顯示數據點
blog

1、plot():教程

       繪製每一個向量對字符串

    繪製每一個向量對,默認爲x=[1,....,n]it

       例1:io

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

2、hold on/off:function

   使用hold能夠把兩幅圖放到一塊兒

   例2

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

 

 

3、繪圖風格:

使用一個字符串定義繪製風格。如「*--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^-'); 

 

 

4、legend()

   添加圖例:legend('L1',...)

   例4:

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

 

 

5、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)');

 

6、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,'*');

 

7、將圖形保存到文件中

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

 

相關文章
相關標籤/搜索