How to share data with a running callback in an App Designer app?

1 次查看(过去 30 天)
I have an App Designer app that executes a while loop (within a callback) once a button is pressed. I want the user to be able to change configurable parameters in the GUI (e.g. a spinner or an edit field) and have those updated values get used by the code currently executing within the while loop running in the original callback.
I've tried having the while loop code read the app.SpinnerName.Value, but this value seems to stay static (from the perspective of the while loop) even though the user can change this value in the GUI while the while loop is executing. I believe this is because the "app" structure that gets passed into the original button callback is a copy of the actual app structure. Is there a way to update or refresh this "app" structure within an executing callback?
I've contemplated alternative approaches to feeding that value in, such as having the SpinnerNameValueChanged callback write the value to a file or perhaps to the base workspace, then having the executing callback read the new value from there (instead of from the app structure), but this strikes me as clunky/inefficient. Any suggestions?

回答(1 个)

Voss
Voss 2022-3-4
Try including a drawnow() inside your while loop, which will update the graphics so that when subesquent code gets the value of a property of a UI component, the value is up-to-date.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by