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!