Is there an example of a GUI with a constantly-updating figure?

25 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2020-7-27
The attached GUIs demonstrate two ways of going about this. To run the GUIs you can execute the MATLAB files with the ".m" extension.
(Note: This references an older version of MATLAB that uses GUIDE, which is no longer recommended and will be removed in a future release. We now suggest using MATLAB App Designer to build GUIs.)
Both GUIs will, upon pressing the "Start" button, repeatedly plot a random line in the axes. Pressing the "Stop" button stops this process. The first GUI updates the plot as fast as possible. The second GUI updates the plot at a fixed, slower, rate.
Case 1: updating_example1
This GUI uses indefinitely-executing loop in the "Start" button's callback to implement the plotting. Each time the body of the loop is executed, a new line is plotted in the axes.
Breaking this loop is accomplished via a flag in the "handles" structure, which is set by an interrupting "Stop" callback. A DRAWNOW in the loop, and appropriately set "Interruptible" property, is necessary to allow this interruption, and allow the drawing events to be processed.
Case 2: updating_example2
This GUI uses a TIMER object, whose "TimerFcn" callback implements the plotting. The "Start" and "Stop" buttons start and stop the timer.
In both GUIs, there are a few special details that need to be addressed:
1) The figure's GUI-data may become out-of-sync with the local "handles" variable, so the GUIDATA function needs to be strategically used to put them back in sync.
2) One must handle the possibility of the "Start" or "Stop" button be pressed twice in a row.
3) One must handle the possibility that the figure is closed while the update loop or timer is still running.
Each GUI's program file has comments to explain how these issues are dealt with in each case.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by