Lagging with updating a Figure
11 views (last 30 days)
Show older comments
I am having an issue when it comes to a figure I have in a GUI. I have it so that an filled object updates its position and moves around the plot based on the input from an accelerometer that is hooked up to my computer. I have it moving around in the way I want however after not very much time the figure begins to lag more and more. I havent yet found a way to fix this issue. If you have an ideas or ways to fix this your help would be much appreciated.
2 Comments
Stephen23
on 10 Mar 2015
Edited: Stephen23
on 10 Mar 2015
How are you plotting this? What code are you using? There a many ways to plot data using MATLAB, and there are also many ways to access and change that plotted data, so how do you expect us to know what you are doing if you do not give us any information at all?
There are lots of talented people here who volunteer their time to help others, but they can't read minds and they can't read your computer screen. Please help them by reading this, and following its advice:
In particular you can upload code using the paperclip button, and please explain exactly how you are using/calling your code, and what you expect it to do.
Accepted Answer
Stephen23
on 11 Mar 2015
Edited: Stephen23
on 11 Mar 2015
Although you don't give any information about the figure and axes properties (e.g. use of hold, the DrawMode or NextPlot properties), based on the information that you gave it may be due to the repeated calling of fill:
fill(handles.E + r*cos(t),handles.N + r*sin(t),'y');
which creates a new patch object on every call. This might mean that the axes are slowly filling up with patch objects, or that MATLAB is somehow trying to keep track of every patch object you have created (i.e. a history). Rather than create a new patch object on every iteration, consider instead creating the patch object before the first iteration, and then using set to update its properties. You will need to use the patch handle for this:
h = fill(...);
and read the patch properties documentation and decide which properties you wish to update on each iteration.
In my experience updating patch/line properties does not result in lagging pictures with the iteration progress, and is a conceptually neater way of programming than creating a new patch object on every iteration.
4 Comments
More Answers (1)
Image Analyst
on 12 Mar 2015
I think Stephen is probably right. You're using up more and more memory and it slows down. I know that, in older versions of MATLAB, when I would repeatedly call imshow() it would store all those images, just covering up the one before, using up more and more memory until it ground to a halt. I could call cla or cla('reset') before I put stuff into the axes and that seemed to fix it with no slowdown anymore. Try clearing out old clutter from your axes by calling cla and see if that helps.
0 Comments
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!