How do I hold plots from a for loop?

18 ビュー (過去 30 日間)
gsourop
gsourop 2017 年 2 月 7 日
コメント済み: Jan 2017 年 2 月 7 日
Hi everyone,
I am trying to hold the plots produced in a for loop but I only get the last plot. What I have done so far is the following.
for i=1:30
plot(y(:,i))
hold;
end
Thanks in advance.
  1 件のコメント
Adam
Adam 2017 年 2 月 7 日
編集済み: Adam 2017 年 2 月 7 日
What is y? Or rather what size is it?
You should always use the
plot( hAxes,... )
version of the plot command, to specify a specific axes, especially if you are expecting 30 different figures as your comment to the answer below suggests.
It's not obvious how you want 30 different figures, but also want to hold the plots within a figure though. What are you expecting on each of these 30 figures?

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

採用された回答

KSSV
KSSV 2017 年 2 月 7 日
編集済み: KSSV 2017 年 2 月 7 日
for i=1:30
plot(y(:,i))
hold on
end
Or simply
plot(y)
  4 件のコメント
KSSV
KSSV 2017 年 2 月 7 日
Or you might be expecting this:
figure;
hold on;
y = rand(5,30) ;
for i=1:5
subplot(5,1,i) ;
plot(y(i,:))
end
Jan
Jan 2017 年 2 月 7 日
+1: Now we find all possible solutions which might match the question.
Calling hold on repeatedly inside a loop seems like a wast of time for me. Although it will be some microseconds only, I prefer:
hAxes = axes('NextPlot', 'add'); % See source of: hold
for k = 1:5
plot(hAxes, y(:, k));
end
or for older Matlab versions, which used doubles as handle of the GUI objects:
plot(y(:, k), 'Parent', hAxes);
to avoid a misinterpretation of the handle as X-value.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by