2017-06-03 42 views
3

我有以下代碼Matlab。情節

T = [0:1:30] 
a = [5:1:35]; a2 = [0:1:30]; 
b = [-4:1:26]; b2 = [12:1:42]; 
c = [16:1:46]; c2 = [15:1:45]; 
d = [2:1:32]; d2 = [-5:1:25]; 
figure(1) 
title('Time histories of output variables (measured vs estimated)') 
subplot(411),plot(T,a, T,a2,'r'); grid; ylabel('p (°/s)'); 
subplot(412),plot(T,b, T,b2,'r'); grid; ylabel('r (°/s)'); 
subplot(413),plot(T,c, T,c2,'r'); grid; ylabel('phi (º)'); 
subplot(414),plot(T,d, T,d2,'r'); grid; ylabel('ay (m/s2)'); 
legend('measured','estimated','Location','bestoutside') 
xlabel('Time [s]'); 

產生以下情節 enter image description here

我想有劇情之外,所有他們的傳說仍然與正常大小外的地方傳說。 (所以傳說應該是在那些紅色圓圈中的一個。任何解決方案?

回答

4

您可以添加另一個subplot作爲空區。僅握住legend,與軸的知名度關閉和圖線的'YData'nan值,所以他們不渲染:

figure(1); 
hSub = subplot(511); plot(1, nan, 1, nan, 'r'); set(hSub, 'Visible', 'off'); 
subplot(512); plot(T, a, T, a2, 'r'); grid; ylabel('p (°/s)'); 
subplot(513); plot(T, b, T, b2, 'r'); grid; ylabel('r (°/s)'); 
subplot(514); plot(T, c, T, c2, 'r'); grid; ylabel('phi (º)'); 
subplot(515); plot(T, d, T, d2, 'r'); grid; ylabel('ay (m/s2)'); 
xlabel('Time [s]'); 
legend(hSub, 'measured', 'estimated', 'Location', 'east'); 

而這裏的結果:

enter image description here

+0

我按照您的建議直接運行代碼,空子圖在那裏,但圖例沒有顯示出來。我收到錯誤「Warning:Plot empty。 >在286的傳說中」 –

+0

@FernandoBastosGarcía:你正在運行什麼版本的MATLAB? – gnovice

+0

2013B。無論如何,我找到了一個解決方案,plot(1,1,1,1,'r'),而不是nans –

0

嘗試獲得使用get方法手柄位置和手工做一些算術改變位置。例如,

T = [0:1:30]; 
a = [5:1:35]; a2 = [0:1:30]; 
b = [-4:1:26]; b2 = [12:1:42]; 
c = [16:1:46]; c2 = [15:1:45]; 
d = [2:1:32]; d2 = [-5:1:25]; 
figure(1) 

title('Time histories of output variables (measured vs estimated)') 

f1 = subplot(411);plot(T,a, T,a2,'r'); grid; ylabel('p (°/s)'); 
pos_f1 = get(f1,'Position'); 
hl = legend('measured','estimated','Location','bestoutside'); 
pos_hl = get(hl, 'Position'); 

subplot(412),plot(T,b, T,b2,'r'); grid; ylabel('r (°/s)'); 
subplot(413),plot(T,c, T,c2,'r'); grid; ylabel('phi (º)'); 
subplot(414),plot(T,d, T,d2,'r'); grid; ylabel('ay (m/s2)'); 

set(hl,'Position',[pos_f1(1)+pos_f1(3)-pos_hl(3)... 
pos_hl(2)+pos_hl(4)+0.015... 
pos_hl(3)... 
0.5*pos_hl(4)]); 

這應該給你:subplot with changed position

您可能需要玩的最後一行中的參數,但你的想法