2011-08-22 17 views
-2

同じウィンドウ内のすべての繰り返しでデータをプロットできないのはなぜですか? drawnowで試しましたが、動作しません。コード:Matlabのプロット 'while'ループ

t=0; 
T=10; 
i =1; 

while t<T 
. . . 

time(i)=(i-1)*delta_t; 

scrsz = get(0,'ScreenSize'); 

figure('position',[80 60 scrsz(3)-110 scrsz(4)-150]); 

subplot(1,3,1); 
plot(time(i),configurations(1,1,i),'-b','LineWidth',2), hold on; 
drawnow; 
xlabel('Time[s]'); 
ylabel('X [m]'); 

subplot(1,3,2); 
plot(time(i),configurations(3,1,i),'-b','LineWidth',2), hold on; 
drawnow; 
xlabel('Time[s]'); 
ylabel('Z [m]'); 

subplot(1,3,3); 
plot(time(i),configurations(2,2,i),'-b','LineWidth',2), hold on; 
drawnow; 
xlabel('Time[s]'); 
ylabel('\phi [deg]'); 

t=t+1; 
i=i+1; 

end 
+0

「動作していません」と定義してください。 –

+0

すべての反復で新しいウィンドウにデータをプロットします。私は最後に10個のプロットウィンドウを持っています。 – Makaroni

答えて

2

あなたはwhileループ内figure('...')ラインを追加しましたので、それはです。それで、繰り返しごとに新しいウィンドウが開きます。その行とscrsz=...行を移動してwhile t<T行のすぐ上に置きます(つまり、外側にはループがあります)。複数のFigureウィンドウにプロットに

、使用がそうのようなハンドルを軸:

hFig1=figure(1);hAxes1=axes; 
hFig2=figure(2);hAxes2=axes; 

while ... 
    --- 
    plot(hAxes1,...) 
    plot(hAxes2,...) 
end 

しかし、各subplotは、独自の軸を作成します。したがって、ループ内の2つの異なるウィンドウで複数のサブプロットにプロットする場合は、ループをより前にに設定してからaccodringlyを呼び出す必要があります。すなわち、

hFig1=figure(1); 
hAxes1Sub1=subplot(1,2,1); 
hAxes1Sub2=subplot(1,2,2); 

hFig2=figure(2); 
hAxes2Sub1=subplot(1,2,1); 
hAxes2Sub2=subplot(1,2,2); 

while ... 
    --- 
    plot(hAxes1Sub1,...) 
    plot(hAxes2Sub1,...) 
end 
+0

同じループ内に別々の2つのプロット関数があるとしますか?何とかこの人物の名前を付けることはできますか? – Makaroni

+0

私は 'scrsz'と 'h = figure(' position '、[80 60 scrsz(3)-110 scrsz(4)-150]); whileループの上、ループ 'plot(h、time(i)、configurations(1,1、i)、' -b '、' LineWidth '、2)、hold on;'失敗。 – Makaroni

+0

@Makaroni今すぐ編集を参照してください。 – abcd