subplot doesn't hold when plotting in for loop

7 ビュー (過去 30 日間)
kukke swaroop
kukke swaroop 2016 年 5 月 16 日
コメント済み: kukke swaroop 2016 年 5 月 16 日
I'm trying to subplot many signals with time in a single figure using subplot by using command 'hold on' in a for loop.
Ex: x is a structure with time
s=[];
plotpos=0.85;
for i=1:10;
s(i)=subplot(10,1,i,'Position', [0.175, plotpos, 0.8, 0.115]);
hold (s(i),'on'); grid on;
plot(x.time,x.signals.values(:,i))
plotpos=plotpos-0.14;
end
It deletes the previous subplots and adds a new one at next position instead of holding all previous subplots and adding new ones at new position.
  1 件のコメント
Jan
Jan 2016 年 5 月 16 日
I've formatted your code. Please use the "{} Code" button. Thanks.

サインインしてコメントする。

採用された回答

Jan
Jan 2016 年 5 月 16 日
Create the axes at first:
s = [];
plotpos = 0.85;
for i = 1:10
s(i) = axes('Position', [0.175, plotpos, 0.8, 0.115], ...
'NextPlot', 'add', ... % as done inside HOLD command
'Grid', 'on');
plotpos = plotpos-0.14;
end
Draw afterwards as often as you want:
for k = 1:10
plot(x.time, x.signals.values(:, k), 'Parent', s(k));
end
  1 件のコメント
kukke swaroop
kukke swaroop 2016 年 5 月 16 日
Perfect! Thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by