How to update GUI in matlab App during a callback

55 次查看(过去 30 天)
Hello
Environement: matlab R2021b and R2021a, windows 10
I would like to change the color of a button during a callback in an Matlab App created with the App Designer.
% Button pushed function: LoadButton
function LoadButtonPushed(app, event)
set(app.LoadButton,'BackgroundColor',[1, 0, 0])%set color of the button to red
%... do things..
set(app.LoadButton,'BackgroundColor',[0, 1, 0])%set color of the button to green
end
I see only the green button in the end, but not the red button while the callback function is running. It seems that there is something like a refresh or update, somthine like guidata in GUIDE is needed.
How do I update the user interface inbetween?
Many thanks and best wishes

采纳的回答

Bruno Luong
Bruno Luong 2022-4-21
Try to force refresh with drawnow
% Button pushed function: LoadButton
function LoadButtonPushed(app, event)
set(app.LoadButton,'BackgroundColor',[1, 0, 0])%set color of the button to red
drawnow
%... do things..
set(app.LoadButton,'BackgroundColor',[0, 1, 0])%set color of the button to green
drawnow
end
  4 个评论
Timo
Timo 2022-4-21
编辑:Timo 2022-4-21
Works perfectly. Many thanks Bruno!

请先登录,再进行评论。

更多回答(1 个)

Hiro Yoshino
Hiro Yoshino 2022-4-21
the changes made by valuChanged callback functions are reflected later. If you want to see the changes dinamically, you should use valuChanging callback functions.

类别

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

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by