Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB 程式設計入門篇 二維平面繪圖 (part2)

Similar presentations


Presentation on theme: "MATLAB 程式設計入門篇 二維平面繪圖 (part2)"— Presentation transcript:

1 MATLAB 程式設計入門篇 二維平面繪圖 (part2)
改自張智星講義 清大資工系 多媒體檢索實驗室

2 3-3 圖軸的控制 plot 指令會根據座標點自動決定圖軸範圍 也可以使用 axis 指令指定圖軸範圍 使用語法:
axis([xmin, xmax, ymin, ymax]) xmin , xmax:指定 x 軸的最小和最大值 ymin , ymax:指定 y 軸的最小和最大值

3 圖軸控制範例-1 (I) 畫出三角函數波在 x 軸介於 11.5 和 20 的部份 範例:
x = linspace(0,8*pi); % 起始與結束元素為 0 及 8*pi y = sin(x/2)+cos(x); plot(x, y); axis([11.5, 20, -inf, inf]); % 將x與y的座標上下界做變更

4 圖軸控制範例-1 (II) axis([11.5, 20, -inf, inf]); inf指令:
以資料點(上例: y 軸的資料點)的最小和最大值取代之 Y的最大值 axis Y的最小值

5 Subplot subplot 在一個視窗產生多個圖形(圖軸) 一般形式為 subplot (m, n, p) 將視窗分為 m ×n 個區域
下一個 plot 指令繪圖於第 p 個區域 p 的算法為由左至右,一列一列

6 圖軸控制範例-4 (I) 同時畫出四個圖於一個視窗中 範例3-13:plotxy13.m x = 0:0.1:4*pi;
subplot(2, 2, 1); plot(x, sin(x)); % 此為左上角圖形 subplot(2, 2, 2); plot(x, cos(x)); % 此為右上角圖形 subplot(2, 2, 3); plot(x, sin(x).*exp(-x/5)); % 此為左下角圖形 subplot(2, 2, 4); plot(x, x.^2); % 此為右下角圖形

7 圖軸控制範例-4 (II) Subplot(2,2,1) Subplot(2,2,2) Subplot(2,2,3)

8 grid 和 box 指令 畫出格線或畫出圖軸外圍的方形 指令 說明 grid on 畫出格線 grid off 取消格線 box on
畫出圖軸的外圍長方形 box off 取消圖軸的外圍長方形

9 3-4 加入說明文字 在圖形或圖軸加入說明文字,增進整體圖形的可讀性 指令 說明 title 圖形的標題 xlabel x 軸的說明
ylabel y 軸的說明 zlabel z 軸的說明(適用於立體繪圖) legend 多條曲線的說明 text 在圖形中加入文字 gtext 使用滑鼠決定文字的位置

10 說明文字範例-1 (I) 範例: subplot(1,1,1); x = 0:0.1:2*pi; y1 = sin(x);
y2 = exp(-x); plot(x, y1, 'b--', x, y2, 'ro'); xlabel('t = 0 to 2\pi'); ylabel('values of sin(t) and e^{-x}') title('Function Plots of sin(t) and e^{-x}'); legend('sin(t)','e^{-x}');

11 說明文字範例-1 (II) title legend ylabel xlabel

12 說明文字範例-2 (I) text指令 使用語法: text(x, y, ‘string’) x、y :文字的起始座標位置
範例3-16:plotxy16.m x = 0:0.1:2*pi; plot(x, sin(x), x, cos(x)); text(pi/4, sin(pi/4), '<- sin(\pi/4) = 0.707'); text(5*pi/4, cos(5*pi/4), '<- cos(5\pi/4) = ');

13 說明文字範例-2 (II)

14 gtext指令 使用語法 gtext(‘string’) 在圖上點選一位置後,string 顯示在其上。 gtext 只能用在二維平面繪圖

15 課堂練習一 The Taylor series of a real or complex function f(x) that is infinitely differentiable in a neighborhood of a real or complex number a, is the power series Reference from Wikipedia degree

16 課堂練習一 請寫一個函數TaylorSin,吃的input為a f(x)為sin(x) 畫出degree分別為1,3,5,7
使用legend Title寫 ‘The Taylor series of sin at a’ x軸的範圍定義在(a-10,a+10),也就是畫這個範圍的函數。


Download ppt "MATLAB 程式設計入門篇 二維平面繪圖 (part2)"

Similar presentations


Ads by Google