台湾国立大学郭彦甫Matlab教程笔记(9) basic plotting
臺灣國立大學郭彥甫Matlab教程筆記(9)
today:
1.basic plotting
2.graphical objects properties
basics
matlab has a powerful plotting engine that can generate a wide variety of plots
plot from ‘‘data’’
1.matlab does not understand functions f(t)=sin(2pit)
2.strategies:
generate the numetic values
data point
function
plot()
matlab會 refresh ,把之前的圖給清掉,如果 想保留,用 指令 hold on
下面是sin和cos的圖像
plot(cos(0:pi/20:2*pi)); hold onplot(sin(0:pi/20:2*pi));plot style
plot(x,y,‘str’)plots each vector pairs(x,y ) using the format defined in str (check linespec)
畫 marker
如果想要sin函數 用圈圈,顯示紅色 需要這樣添加
o表示circle圈圈,r表示red紅色
如果想要cos函數用叉叉,綠色。則如下:xg
legend()函數
add legend to graph 添加圖標 legend(‘L1’,‘L2’,‘L3’…)
position adjustment
畫圖:
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個函數,用一個plot畫出來。
'bd-'表示:blue diomond solid line 意思是藍色的,鉆石(棱形)的,實線
'gp:'表示: green five-point star dotted line 意思是 綠色的五角星表示的點線
'ro-'表示: red circle solid line 紅色的圓圈的實線
'c^-'表示: cyan up triangle solid line 青色,上三角,實線
沒有legend的時候 ,
現在為了區分這四個函數,需要添加legend圖標
效果圖:
title() and lable()
title()
xlable()
ylable()
zlable()
例程:
x=0:0.1:2*pi; y1=sin(x); y2=exp(-x);%兩個函數 plot(x,y1,'--*',x,y2,':o');%畫圖 xlabel('t=0 to 2\pi');%x軸 ylabel('values of sin(x) and e^{-x}');%y軸 title('Function plots if sin(x) and e^{-x}');%標題 legend('sin(x)','e^{-x}');%曲線圖標效果:
注意:反斜杠\ +pi 這樣顯示的話 直接是Π ,在字符串里面
text() and annotation()
問題:積分符號怎么顯示呢?
text with mathematical expression using Latex
這個積分符號是用text()函數寫的 ,text函數前兩個參數是坐標,畫在哪兒。第三個參數是 積分 這個變量str,后面是一個插值
slash 反斜杠 \int 是∫符號
積分的表示:
前后都有兩個$$,然后是積分符號,\int_ 然后是上下限 {0}^{2},之后就是一個被積函數 x^2\sin(x) dx
箭頭使用annotation 畫的 ,arrow, X的位置變化 ,Y的位置變化
代碼:
效果圖;積分的顯示
作業題:
我的練習代碼:
t=1:0.01:2; f=t.*t; g=sin(2*pi*t); %畫圖 plot(t,f,'k-',t,g,'or'); %坐標軸和標題 xlabel('Time (ms)'); ylabel('f(t)'); title('Mini Assignment #1'); %標注函數 legend('t^2','sin(2\pit)');效果圖:
[總結】
本文記錄了基本的繪圖知識。主要是text()函數顯示積分,還有一些畫線的style風格。
總結
以上是生活随笔為你收集整理的台湾国立大学郭彦甫Matlab教程笔记(9) basic plotting的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 台湾国立大学郭彦甫Matlab教程笔记(
- 下一篇: 台湾国立大学郭彦甫Matlab教程笔记(