MATLAB Answers

App Designer not changing Edit Field Value after button is pushed

119 ビュー (過去 30 日間)
AdamG2013468
AdamG2013468 2019 年 6 月 20 日
コメント済み: Pablo López 2020 年 7 月 11 日
Using the callback below, I am trying to print text to a "status bar" (Edit Field Text) before the body of the function is reached to indicate that the App is "processing". At the end of the script, I am printing "STATUS: Complete" to indicate that the funcion is done running. The "STATUS: Complete" text has no trouble being displayed in the edit text field, but i can't get it to print the initial STATUS text.
My code is arranged like so:
function ButtonPushed(app, event)
app.StatusField.Value = 'STATUS: Processing...';
[body of function....]
app.StatusField.Value = 'STATUS: Complete';
end

  0 件のコメント

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 6 月 20 日
編集済み: Adam Danz 2019 年 6 月 20 日
Try this
function ButtonPushed(app, event)
app.StatusField.Value = 'STATUS: Processing...';
drawnow() % <---- tell matlab to update now
[body of function....]
app.StatusField.Value = 'STATUS: Complete';
end

  3 件のコメント

AdamG2013468
AdamG2013468 2019 年 6 月 20 日
Excellent, what a simple fix!
Thanks!
Adam Danz
Adam Danz 2019 年 6 月 20 日
High five!
Pablo López
Pablo López 2020 年 7 月 11 日
Perfect solution! Works perfectly.
Just a tip. If anybody needs to update a percentage value for example, and the proposed function make the change imperceptible, you can also use the next code.
function ButtonPushed(app, event)
app.StatusField.Value = 'STATUS: Processing...';
pause(0.01) % You create a delay of 10ms to update your value
[body of function....]
app.StatusField.Value = 'STATUS: Complete';
end
Hope that helps!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by