I am trying to detect if a GUI created from AppDesigner is open

조회 수: 40 (최근 30일)
Harry Spratt
Harry Spratt 2022년 4월 1일
댓글: Benjamin Kraus 2022년 4월 1일
I am trying to detect if a GUI created from AppDesigner is open. Does anyone know how to do this with AppDesigner GUI's?
I have tried and looked around a few posts such as these:
but i havnt had any luck it making it work.
Essentially I have an app which creates parameters for the rest of the script such as variables. I don't want the rest of the script to run till the mlapp GUI has a button pressed. My take was to set up a wait loop checking that the GUI is still open and when its closed the loop will continue. Is this a good way about it / how do i make this work?

답변 (1개)

Benjamin Kraus
Benjamin Kraus 2022년 4월 1일
You said: "My take was to set up a wait loop checking that the GUI is still open and when its closed the loop will continue. Is this a good way about it / how do i make this work?"
It sounds like you are looking for the waitfor command, which will block your code execution until the corresponding figure has closed. For example:
f = uifigure;
disp("Waiting")
waitfor(f)
disp("Figure Closed")
  댓글 수: 1
Benjamin Kraus
Benjamin Kraus 2022년 4월 1일
There might be a second part to your question, which is "how do I get the handle to the figure".
  • If you are using App Designer, the handle the figure is stored in a property on the App. By default that property is named "UIFigure". You can pass that value into waitfor.
  • The preferred approach would be to use an existing figure handle (which is stored when the figure or uifigure command was called), but if you don't have that for some reason, you can use findall on groot to find all open figures, then check the Name to make sure you have the correct figure.
uifigure('Name','My App'); % Forgot to store the output handle.
uifigure(); % Another unrelated figure that happens to be open.
% Use findall to find the handle for the figure with the name "My App".
f = findall(groot,'Type','figure','Name','My App');
waitfor(f)
disp("Figure Closed")

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by