How do I update a plot in a figure without closing the gui and without the plots stacking on top of each other?
9 views (last 30 days)
Show older comments
I have a hardcoded gui that takes user inputs in some text fields and updates a graph based on the inputs when a button is pressed. When I press the button to update the figure, instead of the graph updating, a new graph is just created on top of the old graph which causes things to not look very good. How do I make it so that either the graph updates, or the old graph is deleted.
Note: I have tried refresh, linkdata, and drawnow but either they do not fit the situation or I am not using them right. I've attached the code for reference.
0 Comments
Answers (1)
Swatantra Mahato
on 23 Oct 2020
Hi,
I am assuming that you want to update the plot generated without closing the GUI and without a new plot being created.
A new graph is created each time because of the following line in the funciton physEngineGUI1:
ax = axes(f, 'Units', 'Normalized', 'position', [0.32, 0.12, 0.65, 0.80]);
A new axes object is created each time the function "physEngineGUi1" is called (It is called on every callback). Similarly the other UI objects are also created more than once - this can be confirmed by executing
f.Children
on the MATLAB command line to see the objects present in the figure.
In order to prevent this without closing and reopening the figure, you may want to look into modifying your code so that the axes and other objects are created only once and not every time a button is pressed.
Hope this helps
0 Comments
See Also
Categories
Find more on Annotations 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!