How do I update a plot in a figure without closing the gui and without the plots stacking on top of each other?
14 views (last 30 days)
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.
Swatantra Mahato on 23 Oct 2020
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
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