matlab學習筆記(一)---二維繪圖

1、基本繪圖指令

鍵入如下指令:

  x=linspace(0,2*pi,100);
 plot(x,sin(x),'co',x,cos(x),'g*');

圖像如下:



加上一下註解:

  axis([0,2*pi,-1,1]);
  xlabel('x軸');
  ylabel('y軸');
  title('正弦和餘弦函數圖像');
  legend('y=sin(x)','y=cos(x)');
  grid on

圖像如下:



2、繪圖選擇

鍵入如下指令可放大縮小圖形:

   M=peaks(25);
   plot(M);
   zoom on
   zoom out

圖形如下:




快速畫圖:

  fplot('sin(x)./x',[-20 20 -0.4 1.2]);

圖形如下:


3、特殊的二維圖形的繪製

a.彗星狀軌跡繪製的例子:

 x=-pi:pi/100:pi;
  y=tan(sin(x))-sin(tan(x));
  comet(x,y);

圖像如下:




b.極座標的例子:

 t=0:.1:8*pi;
  r=cos(5*t/4)+1/3;
  polar(t,r);

圖像如下:

c.其他1

    x=-2:0.1:2;y=sin(x);
   subplot(221);
   feather(x,y);xlabel('(a) feather()')
   subplot(222);
   stairs(x,y);xlabel('(b) stairs()')
   subplot(223);
   stem(x,y);xlabel('(c) stem()')
   subplot(224);
   fill(x,y,'r');xlabel('(d) fill()')

圖像如下:


d.其他2

     t=-10:1:10;
    subplot(221);
    bar(t,cos(t));
    subplot(222);
    compass(t,cos(t));
    subplot(223);
    rose(t,cos(t)); 
    subplot(224);
    fill(t,cos(t),'b');

圖像如下:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章