Is there an example of a GUI with a constantly-updating figure?
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 21 Gen 2010
Modificato: MathWorks Support Team
il 27 Lug 2020
I would like my GUI to include a constantly-updating figure, but am not sure how to go about this.
Risposta accettata
MathWorks Support Team
il 27 Lug 2020
Modificato: MathWorks Support Team
il 27 Lug 2020
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.
1 Commento
Walter Roberson
il 10 Lug 2020
It looks to me as if likely the code framework is the same as is posted at https://www.mathworks.com/matlabcentral/answers/92157-figure-gui
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!