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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2017년 2월 13일

댓글:

2017년 2월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by