How to keep lines on a changing plot ?
Mostrar comentarios más antiguos
Hello,
I have an axe :
S.a_axe = axes(...);
On this axe I'm plotting some data, but I'm making it in a loop, so that every couple of seconds another data set is ploted. So the image is changing all the time. I would like to plot on it lines, but the problem is, that this lines must be always on the plot. Is there an easy way to plot lines on a plot. I mean to set them as the first seen object. Or do I have to create them always new after every plot.
Thank you, Adrien
Respuesta aceptada
Más respuestas (2)
Orion
el 5 de Nov. de 2014
use the hold function
S.a_axe = axes();
hold on;
for i=1:10
plot(i*sin(0:0.01:10));
end
by default matlab replace the plot at each call of plot, unless you hold it.
2 comentarios
Adrien
el 5 de Nov. de 2014
Orion
el 5 de Nov. de 2014
You could play with the order of the children in the axe.
% create an axe and some plots.
axes();
hold on;
for i=1:10
plot(i*100*sin(0:0.01:10));
end
pause(1)
% then add an image : will be over the lines
image(imread(which('street1.jpg')));
pause(1)
% inverse the children of the current axe
set(gca,'children',flipud(get(gca,'children')))
Mike Garrity
el 5 de Nov. de 2014
Probably the simplest approach would be to save a handle to the image object and then just set its CData when you want to change the image.
h = image(first_img)
hold on
for i=1:10
plot(...)
end
pause(1)
set(h,'CData',next_img)
In this way, the order of the image won't change relative to the other things you plotted. All that's changing is the contents of the image.
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!