Plotting areas in a for loop

1 回表示 (過去 30 日間)
Luke Marsden
Luke Marsden 2017 年 2 月 13 日
コメント済み: Star Strider 2017 年 2 月 14 日
I am trying to plot areas inside a for loop. However, only the area for the final pass of the loop is plotting.
ylim = get(gca, 'Ylim');
for k = 1:length(explosions);
area([explosions(k, 1) explosions(k, 2)], [ylim(2) ylim(2)]);
end
The explosions vector is a 26x2 matrix that contains the start and end time of the area to plot in the first and second column respectively.

採用された回答

Star Strider
Star Strider 2017 年 2 月 13 日
Without seeing the rest of your code, I can only guess) that you are not using the hold function.
Try something like this:
figure(1)
ylim = get(gca, 'Ylim');
for k = 1:length(explosions);
area([explosions(k, 1) explosions(k, 2)], [ylim(2) ylim(2)]);
hold on
end
hold off
  2 件のコメント
Luke Marsden
Luke Marsden 2017 年 2 月 14 日
Silly me...thanks!
Star Strider
Star Strider 2017 年 2 月 14 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by