Setting plot handle x,y,z data does not clear "old data"

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

Ryan - are you sure that the old markers were created using plotHandle and not some other handle (that may or may not captured)? What are the different commands that you are using to update your figure (with graphics)?
When I change the marker, I call
set(plotHandle,'Marker','.')
Or whatever plot symbol I want to use.
So do all of your plots (or whatever else you are using to add graphics to the axes) make use of plotHandle? Are you sure that there isn't another handle being used?
Here are some more specifics. I am plotting radar returns. I have created a PPI (planned position indicator, a regular radar display showing bearing and range), and each element has its own plot handle. Then as the data comes in, I have a unique plot handle for each type of return (ie., different airlines). So I have handles like h_united, h_american, h_delta, etc. when I need to update one of the plots, I'll use set(h_united,...). When I need to change the symbology, I do set(h_delta,'Marker',...). After that, I call drawnow to force the update. The change is made, but right on top of what I wnated changed. So in the case of changed symbology, I'll have the original square, then the new dot right on top of the square.
Could you post a sample of the code, or at the very least, make a list of all the calls to plot and ensure that in each call, you are saving the handle to it. Once you have saved the handle, how do you pass it around? It sounds like you may have a GUI of some kind (is this the case?) so what are you using to keep track of all the handles returned from plot?
This does not seem like it needs extreme speed. Why can't you just plot it all over again to update it? I mean, how much time would that take? I would think it would take only a fraction of a second like most calls to plot(). Does it take longer, like several seconds?
Perhaps replotting is the best thing to do. Basically what I have is a model view controller. The plot handles are properties of the view object (GUI). The code looks something like this
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
And when the user selects a radio button to change the symbology, the following command is called
set(viewObj.h_delta,'Marker','.');
I use listeners to communicate actions to each of the objects, so it gets rather complicated.
Also should point out that the plot handles are public properties of the view object.
Ryan - I don't understand the second condition in your if statement
|| isempty(deltaReturns)
which, when true, means that even if your h_delta is a valid handle to a graphics object, you will overwrite it with a new handle...and so the old one persists. You may want to add some additional code here to separate these two conditions so that if you have a handle AND the deltaReturns is empty the delete the existing handle before calling plot3.
There is the answer. When I filter the data, I pass the data to be plotted to the method that calls the above code. I should instead plot everything individually and set the visibility of the plot, ie,
set(allTargetData(indicesOfTargetsFilteredOut).plotHandle,'Visibility','off')
So al the data is always available, but I only display what I need to. I am looking at something like a total of close to 50 MB of data that would eventually be stored in the allTargetData structure. What kind of performance impacts would that have?
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.
@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.

Sign in to comment.

 Accepted Answer

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.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Asked:

on 16 Jan 2015

Commented:

on 18 Jan 2015

Community Treasure Hunt

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

Start Hunting!