Setting plot handle x,y,z data does not clear "old data"
3 views (last 30 days)
Show older comments
I am plotting information streaming in from a file. Instead of plotting the new data every time, I'm trying to be "efficient" by updating the XData, YData, and ZData with the SET command. I am also trying to to manipulate the data as it is streaming in by doing things like changing the plot marker or filtering the data and only displaying certain data points. Again, all on the fly.
My problem is that when I try to update the symbology, for example, the old markers remain on the plot with the new markers overlaid on top of the old. If I try to filter the data, new data is filtered, and will display when the filter is removed, but old data (that should be filtered) stays on the plot.
I try to clear the data by using
set(plotHandle,'XData',[],'YData',[],'ZData',[]);
to no avail. (I update the data fields with another "set" command later and call "drawnow" when I'm ready to render the plot again.) I could use
cla
but that would cause me to lose the handle all together and I would have to plot the data again, which I am trying to avoid.
Any suggestions?
12 Comments
Image Analyst
on 18 Jan 2015
If Geoff posts it as an answer, I can delete my answer so that you can accept Geoff's answer and he can get reputation points.
Geoff Hayes
on 18 Jan 2015
@Ryan - I've never had to work with that much data (at any one time) so would not be able to provide a clear idea of what the performance impact may be. I still think that if there is data that you are not ever going to use (because it is out of date or whatever) then for sure delete it from your displays.
Accepted Answer
Geoff Hayes
on 18 Jan 2015
A snippet of the code showed that the plot handle was being initialized and perhaps overwritten under certain conditions
if(~isa(viewObj.h_delta,'handle') || isempty(deltaReturns))
viewObj.h_delta = plot3(x,y,z,'MarkerEdgeColor','y','Marker','+');
else
set(viewObj.h_delta,'XData',updatedXDataVector,'YData',updatedYDataVector,...
'ZData',updatedZDataVector);
end
The second condition in the if statement
|| isempty(deltaReturns)
which, when true, would mean that even if the h_delta is a valid handle to a graphics object, it would be overwritten with a new handle...and so the old one would persist and the graphics remain on the axes.
The fix may be to add some additional code here to separate these two conditions so that if there is a handle AND the deltaReturns is empty then delete the existing handle before calling plot3.
0 Comments
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!