How do I update a plot in a figure without closing the gui and without the plots stacking on top of each other?
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Swatantra Mahato
2020-10-23
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!