複製鏈接
請複製以下鏈接發送給好友

subplot

鎖定
subplot是MATLAB中的函數,是將多個圖畫到一個平面上的工具。在matlab的命令窗口中輸入doc subplot或者help subplot即可獲得該函數的幫助信息。
中文名
分塊圖
外文名
subplot
函數簡介
subplot是MATLAB中的函數
應用軟件
MATLAB
相似函數
plot()
函數功能
是將多個圖畫到一個平面上的工具

subplot函數功能

subplot是MATLAB中的函數。
使用方法:subplot(m,n,p)或者subplot(m n p)。
subplot是將多個圖畫到一個平面上的工具。其中,m表示是圖排成m行,n表示圖排成n列,也就是整個figure中有n個圖是排成一行的,一共m行,如果m=2就是表示2行圖。p表示圖所在的位置,p=1表示從左到右從上到下的第一個位置。
在matlab的命令窗口中輸入doc subplot或者help subplot即可獲得該函數的幫助信息。

subplot原理介紹

Matlab對subplot() 的解釋是:
SUBPLOT:Create axes intiled positions,意思是在均勻平鋪的位置上生成軸對象,這是一個在Figure對象層次上起作用的函數。 [1] 

subplot功能比較

stem() 函數用來畫一張整圖,畫出來是離散函數。plot() 是連續函數,可以畫一張連續的圖;最一般最常用的畫法。subplot(m,n,p) 是畫一張圖中包含若干子圖,每個子圖也是連續的,可將多個圖畫到一個平面上。

subplot示例程序

subplot示例1

這是如何在MATLAB中創建子圖的示例。您可以在MATLAB版本2016a或更高版本的實時編輯器中打開此示例。 [2] 
%計算圖的數據
fm = 20e3;
fc = 100e3;
tstep = 100e-9;
tmax = 200e-6;
t = 0:tstep:tmax;
xam = (1 + cos(2*pi*fm*t)).*cos(2*pi*fc*t);
T = 1e-6;
N = 200;
nT = 0:T:N*T;
xn = (1 + cos(2*pi*fm*nT)).*cos(2*pi*fc*nT);
%創建跨越2x2網格位置1和3的採樣信號的幹線圖
figure
圖1 程序運行結果 圖1 程序運行結果
subplot(2, 2, [1 3])
stem(nT,xn)
xlabel('t')
ylabel('x[n]')
title('Sampled Every T=1e-6 ')
% 在2x2網格的位置2中為AM調製信號創建xy圖
subplot(2, 2, 2)
plot(t, xam)
axis([0 200e-6 -2 2])
xlabel('t')
ylabel('xam(t)')
title('AM Modulated Signal')
% 在2x2網格的位置4中為重建信號創建xy圖
subplot(2, 2, 4)
plot(nT, xn)
xlabel('t')
ylabel('x_zoh(t)')
title('Reconstruction at T=4e-6 ')
運算的結果如圖1所示。

subplot示例2

% Create the data to be plotted [3] 
TBdata = [1990 4889 16.4; 1991 5273 17.4; 1992 5382 17.4; 1993 5173 16.5;
1994 4860 15.4; 1995 4675 14.7; 1996 4313 13.5; 1997 4059 12.5;
1998 3855 11.7; 1999 3608 10.8; 2000 3297 9.7; 2001 3332 9.6;
2002 3169 9.0; 2003 3227 9.0; 2004 2989 8.2; 2005 2903 7.9;
2006 2779 7.4; 2007 2725 7.2];
measles = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884]';
mumps = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882]';
chickenPox = [37140 32169 37533 39103 33244 23269 16737 5411 3435 6052 12825 23332]';
years = TBdata(:, 1);
cases = TBdata(:, 2);
rate = TBdata(:, 3);
% Create the pie chart in position 1 of a 2x2 grid
figure
subplot(2, 2, 1)
pie([sum(measles) sum(mumps) sum(chickenPox)], {'Measles', 'Mumps', 'Chicken Pox'})
title('Childhood Diseases')
% Create the bar chart in position 2 of a 2x2 grid
subplot(2, 2, 2)
bar(1:12, [measles/1000 mumps/1000 chickenPox/1000], 0.5, 'stack')
xlabel('Month')
ylabel('Cases (in thousands)')
title('Childhood Diseases')
axis([0 13 0 100])
set(gca, 'XTick', 1:12)
% Create the stem chart in position 3 of a 2x2 grid
subplot(2, 2, 3)
stem(years, cases)
xlabel('Years')
ylabel('Cases')
title('Tuberculosis Cases')
圖2 程序運行結果 圖2 程序運行結果
axis([1988 2009 0 6000])
% Create the line plot in position 4 of a 2x2 grid
subplot(2, 2, 4)
plot(years, rate)
xlabel('Years')
ylabel('Infection Rate')
title('Tuberculosis Cases')
axis([1988 2009 5 20])
運算的結果如圖2所示。
參考資料