Plotting areas in a for loop

2 visualizaciones (últimos 30 días)
Luke Marsden
Luke Marsden el 13 de Feb. de 2017
Comentada: Star Strider el 14 de Feb. de 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.

Respuesta aceptada

Star Strider
Star Strider el 13 de Feb. de 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 comentarios
Luke Marsden
Luke Marsden el 14 de Feb. de 2017
Silly me...thanks!
Star Strider
Star Strider el 14 de Feb. de 2017
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by