Hey theret I have a problem when I run this plotting code. I want all elements to be plotted in animation and only the last data point, but I only get one of them like that, the others are plotted in animation but the old data dont delete... Here is the code I'm using:
for i = 1:N
for j = 1:B
p=plot(x(j,i),y(j,i),'bo');
hold on
end
pause(0.001)
delete(p)
end
Thank you

 Respuesta aceptada

Oscar García
Oscar García el 6 de Abr. de 2015

0 votos

Hey I figured it out:
for i = 1:N
for j = 1:B
p(j)=plot(x(j,i),y(j,i),'bo');
hold on
end
pause(0.001)
delete(p)
end
Thanks

Más respuestas (1)

Geoff Hayes
Geoff Hayes el 5 de Abr. de 2015
Editada: Geoff Hayes el 5 de Abr. de 2015

0 votos

Oscar - at which point do you want to delete the data? Once the inner for loop has completed or on every iteration of the inner for loop?
If you just want to show the current point only (with no history) then try updating the graphics handle p rather than deleting it. Something like
hPlot = plot(NaN,NaN);
for i = 1:N
for j = 1:B
set(hPlot,'XData',x(j,i),'YData',y(j,i), ...
'Marker','o','MarkerEdgeColor','b');
pause(0.0001);
end
end

5 comentarios

Oscar García
Oscar García el 5 de Abr. de 2015
Thanks Geoff...I want to delete the data once the inner for loop has completed. The final plot must be B number of elements moving until i=N...
Oscar García
Oscar García el 5 de Abr. de 2015
I've tried your suggestion but matlab returns an error...:
Error using set
Invalid parameter/value pair arguments
Geoff Hayes
Geoff Hayes el 5 de Abr. de 2015
Oscar - I should have tested before posting. Try this instead
set(hPlot,'XData',x(j,i),'YData',y(j,i),'Marker','o','MarkerEdgeColor','b');
Oscar García
Oscar García el 5 de Abr. de 2015
Now I only get plotted the Bth element
Geoff Hayes
Geoff Hayes el 6 de Abr. de 2015
Oscar - please be more specific in what you want.

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Centro de ayuda y File Exchange.

Preguntada:

el 5 de Abr. de 2015

Respondida:

el 6 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by