台湾国立大学郭彦甫Matlab教程笔记(9) basic plotting
臺(tái)灣國立大學(xué)郭彥甫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會(huì) 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函數(shù) 用圈圈,顯示紅色 需要這樣添加
o表示circle圈圈,r表示red紅色
如果想要cos函數(shù)用叉叉,綠色。則如下:xg
legend()函數(shù)
add legend to graph 添加圖標(biāo) 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個(gè)函數(shù),用一個(gè)plot畫出來。
'bd-'表示:blue diomond solid line 意思是藍(lán)色的,鉆石(棱形)的,實(shí)線
'gp:'表示: green five-point star dotted line 意思是 綠色的五角星表示的點(diǎn)線
'ro-'表示: red circle solid line 紅色的圓圈的實(shí)線
'c^-'表示: cyan up triangle solid line 青色,上三角,實(shí)線
沒有l(wèi)egend的時(shí)候 ,
現(xiàn)在為了區(qū)分這四個(gè)函數(shù),需要添加legend圖標(biāo)
效果圖:
title() and lable()
title()
xlable()
ylable()
zlable()
例程:
x=0:0.1:2*pi; y1=sin(x); y2=exp(-x);%兩個(gè)函數(shù) 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}');%標(biāo)題 legend('sin(x)','e^{-x}');%曲線圖標(biāo)效果:
注意:反斜杠\ +pi 這樣顯示的話 直接是Π ,在字符串里面
text() and annotation()
問題:積分符號怎么顯示呢?
text with mathematical expression using Latex
這個(gè)積分符號是用text()函數(shù)寫的 ,text函數(shù)前兩個(gè)參數(shù)是坐標(biāo),畫在哪兒。第三個(gè)參數(shù)是 積分 這個(gè)變量str,后面是一個(gè)插值
slash 反斜杠 \int 是∫符號
積分的表示:
前后都有兩個(gè)$$,然后是積分符號,\int_ 然后是上下限 {0}^{2},之后就是一個(gè)被積函數(shù) x^2\sin(x) dx
箭頭使用annotation 畫的 ,arrow, X的位置變化 ,Y的位置變化
代碼:
效果圖;積分的顯示
作業(yè)題:
我的練習(xí)代碼:
t=1:0.01:2; f=t.*t; g=sin(2*pi*t); %畫圖 plot(t,f,'k-',t,g,'or'); %坐標(biāo)軸和標(biāo)題 xlabel('Time (ms)'); ylabel('f(t)'); title('Mini Assignment #1'); %標(biāo)注函數(shù) legend('t^2','sin(2\pit)');效果圖:
[總結(jié)】
本文記錄了基本的繪圖知識(shí)。主要是text()函數(shù)顯示積分,還有一些畫線的style風(fēng)格。
總結(jié)
以上是生活随笔為你收集整理的台湾国立大学郭彦甫Matlab教程笔记(9) basic plotting的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 台湾国立大学郭彦甫Matlab教程笔记(
- 下一篇: 台湾国立大学郭彦甫Matlab教程笔记(