필터 지우기
필터 지우기

Update app designer field in external function

조회 수: 5 (최근 30일)
Koen
Koen 2020년 5월 15일
댓글: Koen 2020년 5월 15일
I'm designing a Matlab app with the app designer. In the app GUI_mirror_cooling I have a 'run' button that executes a simulation script, sim_cooling_GUI. Since the simulation may take a long time, it would be nice to have a progress field. By calling a GUI_mirror_cooling update function periodically, this text field would be updated.
function RunButtonPushed(app, event)
sim_cooling_GUI(app.GUI_settings) % call the simulation function
end
And in sim_cooling_GUI, when current time is a fraction of the end time:
if t/t_end >= disp_update/100
disp(['Progress: ',num2str(t/t_end*100),'%']) % show progress in matlab command window
disp_update = disp_update + 1; % increment, disp_update/100 could also be used as output
update_progress_indicator(GUI_mirror_cooling,round(t/t_end*100),1); % show progress in app, ETA not yet implemented
end
The time step size is nonconstant, therefore I have a >= with disp_update.
Now, in the app GUI_mirror_cooling,
methods (Access = public)
function update_progress_indicator(app,progress,ETA)
app.ProgressEditField.Value = [num2str(progress),'%']; % progress in percent
app.ExpectedendtimeEditField.Value = num2str(ETA); % ETA, to be implemented
pause(0.001) % allow field to be updated
end
end
This however opens a new app window for every 1 % progress (with the correct progress field value). What I need is that the app window that is already open has its value updated. I have seen similar (old) questions that use handles, however I am unsure how to access the fields of the app window.

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 5월 15일
Koen - it looks like your sim_cooling_GUI is a function (since you are passing in the app.GUI_Settings so why not just pass in the app object as well so that you update its progress rather than creating a new instance of the GUI?
function RunButtonPushed(app, event)
sim_cooling_GUI(app, app.GUI_settings) % call the simulation function
end
and
function sim_cooling_GUI(app, GUI_settings)
% some code
if t/t_end >= disp_update/100
disp(['Progress: ',num2str(t/t_end*100),'%']) % show progress in matlab command window
disp_update = disp_update + 1; % increment, disp_update/100 could also be used as output
update_progress_indicator(app,round(t/t_end*100),1); % show progress in app, ETA not yet implemented
end
So we use the passed in app rather than creating a new instance of the GUI.
  댓글 수: 1
Koen
Koen 2020년 5월 15일
Hello Geoff, thank you for your simple and clear answer. This solves my problem and helps me learn the language!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by