How to keep lines on a changing plot ?
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Adam
2014-11-5
Do you always have an image on the axes?
If so then you don't need to keep replacing the image (and by the way, be careful using hold on with images...I have done that before without thinking and you can end up with 10 images all one on top of another taking up memory even though you only see the top one!).
If you keep the image handle as e.g.
hImage = image( S.a_axe, ... );
you can then replace the data in the image with e.g.
hImage.CData = newImageData;
and it will simply replace the data without changing anything else, including anything else also plotted on the axes.
You will still need to do some replotting of your line the first time though if you plot the line before the first image as the first image will sit on top of the line. But you can follow orion's advice for this initial case of reordering children.
0 个评论
更多回答(2 个)
Orion
2014-11-5
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 个评论
Orion
2014-11-5
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
2014-11-5
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!