Matlab và ứng dụng - Vẽ đồ thị trong Matlab
Khi muốn vẽ thêm đồ thị trên đồ thị hiện có, ta sử dụng
lệnh hold on. Để tắt chế độ này, sử dụng hold off.
Ví dụ
>> x = 0:pi/10:2*pi;
>> plot(x, sin(x),'->r')
>> hold on
>> t =0:1:7;
>> plot(t, 2*t,'-*b');
Tóm tắt nội dung Matlab và ứng dụng - Vẽ đồ thị trong Matlab, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
2/9/2010 1 Vẽ đồ thị trong Matlab [email protected] ĐỒ THỊ 2D Lệnh plot >> plot(x,f(x)) Với: f(x) - hàm số cần vẽ x – vectơ miền giá trị của hàm f [email protected] 2/9/2010 2 Ví dụ hàm plot Vẽ đồ thị của hàm y = sin(x) >> x = 0:pi/100:2*pi; >> y = sin(x); >> plot(x, y) [email protected] [email protected] 2/9/2010 3 >> plot(x,y,’LinestyleMarkerColor’) Linestyle (nét vẽ) ‘-’ ‘--‘ ‘:’ ‘-.’ Tham số đường nét của đồ thị [email protected] Marker (ñánh dấu nét vẽ) ‘+’ + ‘h’/‘hexagram’ ‘o’ ^ ‘*’ * v ‘.’ . > ‘s’/‘square’ < ‘d’/‘diamond’ ‘p’/‘pentagram’ [email protected] 2/9/2010 4 Color (màu sắc) ‘r’ (red) ‘k’(black) ‘w’(white) ‘y’(yellow) ‘c’(cyan) ‘b’(blue) ‘g’(green) ‘m’(magenta) [email protected] Ví dụ vẽ đồ thị với các tham số >> x = 0:pi/20:2*pi; >> plot(x, sin(x),’-.*r’); [email protected] 2/9/2010 5 Lệnh hold on Khi muốn vẽ thêm đồ thị trên đồ thị hiện có, ta sử dụng lệnh hold on. Để tắt chế độ này, sử dụng hold off. Ví dụ >> x = 0:pi/10:2*pi; >> plot(x, sin(x),'->r') >> hold on >> t =0:1:7; >> plot(t, 2*t,'-*b'); [email protected] Ví dụ vẽ nhiều đồ thị với các tham số >> x = 0:pi/20:2*pi; >> plot(x, sin(x),’-.*r’); >> hold on >> plot(x, sin(x – pi/2),’--om’); >> plot(x, sin(x – pi), ‘:bs’); >> hold off [email protected] 2/9/2010 6 [email protected] Các tham số khác LineWidth : độ rộng của nét vẽ, tính bằng pt. MarkerEdgecolor: màu của đường viền marker. MarkerFacecolor: màu bên trong marker. Markersize: độ lớn của marker, tính bằng pt. [email protected] 2/9/2010 7 Ví dụ vẽ đồ thị với các tham số khác >> x = -pi:pi/10:pi; >> y = tan(sin(x)) - sin(tan(x)); >> plot(x,y,‘--rs','LineWidth',… 2,'MarkerEdgecolor',… 'k','MarkerFacecolor',… 'g', 'MarkerSize',10) [email protected] [email protected] 2/9/2010 8 Xác định kiểu trục tọa độ Lệnh axis axis([xmin xmax ymin ymax]) Tùy chỉnh các kiểu trục tọa độ • axis on/off/auto • axis normal/square/equal/tight • axis ij/xy • grid on/off [email protected] Ví dụ về kiểu trục toạ độ [email protected] 2/9/2010 9 Xác định giới hạn tọa độ • xlim([xmin xmax]) • ylim(ymin ymax]) Xác định giới hạn của trục Ox và Oy. Ví dụ x = linspace(0,3,500); y = 1./(x - 1).^2 + 3./(x - 2).^2; plot(x,y); grid on; ylim([0 50]); [email protected] [email protected] 2/9/2010 10 Xác định các mốc ghi trên trục tọa độ • XTick và YTick Ví dụ x = -pi:.1:pi; y = sin(x); plot(x,y) set(gca,'XTick',-pi:pi/2:pi) set(gca,'XTickLabel',… {'-pi','-pi/2','0','pi/2','pi'}) [email protected] [email protected]
File đính kèm:
Matlab và ứng dụng - Vẽ đồ thị trong Matlab.pdf

