Plotting areas in a for loop

1 vue (au cours des 30 derniers jours)
Luke Marsden
Luke Marsden le 13 Fév 2017
Commenté : Star Strider le 14 Fév 2017
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.

Réponse acceptée

Star Strider
Star Strider le 13 Fév 2017
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 commentaires
Luke Marsden
Luke Marsden le 14 Fév 2017
Silly me...thanks!
Star Strider
Star Strider le 14 Fév 2017
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by