Matlab画图函数与参数
#Matlab畫圖函數(shù)及參數(shù)
學(xué)習(xí)資料方便查閱。
##plot函數(shù)
plot是繪制一維曲線的基本函數(shù),但在使用此函數(shù)之前,我們需先定義曲線上每一點(diǎn)的x及y座標(biāo)。下例可畫出一條正弦曲線:
close all;
x=linspace(0, 2*pi, 100); % 100個點(diǎn)的x座標(biāo)
y=sin(x); % 對應(yīng)的y座標(biāo)
plot(x,y);
-
若要畫出多條曲線,只需將座標(biāo)對依次放入plot函數(shù)即可:plot(x, sin(x), x, cos(x));
-
若要改變顏色,在座標(biāo)對后面加上相關(guān)字串即可:
plot(x, sin(x), ‘c’, x, cos(x), ‘g’); -
若要同時改變顏色及圖線型態(tài)(Line style),也是在座標(biāo)對后面加上相關(guān)字串即可:
plot(x, sin(x), ‘co’, x, cos(x), ‘g*’);
參數(shù)設(shè)置如圖:
坐標(biāo)與注解
axis([xmin,xmax,ymin,ymax])函數(shù)來調(diào)整圖軸的范圍:
axis([0, 6, -1.2, 1.2]);
此外,MATLAB也可對圖形加上各種注解與處理:
xlabel(‘Input Value’); % x軸注解
ylabel(‘Function Value’); % y軸注解
title(‘Two Trigonometric Functions’);
legend(‘y = sin(x)’,‘y = cos(x)’); % 圖形注解
grid on; % 顯示格線
##subplot
我們可用subplot來同時畫出數(shù)個小圖形於同一個視窗之中:
subplot(2,2,1); plot(x, sin(x));
subplot(2,2,2); plot(x, cos(x));
subplot(2,2,3); plot(x, sinh(x));
subplot(2,2,4); plot(x, cosh(x));
plot3(三維直線函數(shù))
例:繪參數(shù)方程 x=t;y=sin(t);z=cos(t) 的空間曲線
clf
t=0:0.05:100;
x=t;y=sin(t);z=sin(2*t);
plot3(x,y,z,‘b:’)
###柱狀圖
y = [ 1.072 0.852 0.539 0.628;
3.688 3.154 1.325 1.652;
5.467 5.033 3.658 4.103];
hArray = bar(y,0.8); //0.8是柱狀圖寬度
ylim([-0.5 0.5 ]) //限定坐標(biāo)軸的范圍
x2=[’ Case 1’;'Case 2 '];
set(gca,‘XTickLabel’,x2) //設(shè)置柱狀圖坐標(biāo)
legend(‘location’,‘a(chǎn)’);
string是函數(shù)名稱,location不要改,a可以填northeast表示右上角,southeast表示右下角,northwest表示左上角,southwest表示左下角。
總結(jié)
以上是生活随笔為你收集整理的Matlab画图函数与参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VUE $SET源码
- 下一篇: $nextTick 源码