필터 지우기
필터 지우기

How to prevent App Designer GUI from opening multiple GUI figures?

조회 수: 23 (최근 30일)
Justin Coe
Justin Coe 2019년 2월 5일
댓글: Gee 2022년 3월 24일
I am trying to create a GUI in App Designer that will display values from a Simulink model. Using the add_exec_event_listener I am able to get the GUI to change the value of a numeric EditField based on the model. The problem is that every time the value changes and the GUI should update, it just opens up a new figure that has the new value. It doesn't just change the existing figure to match the new value, which is what I want it to do. I have looked around quite a bit but cannot seem to find anyone else that has posted this problem or anything similar.
My current simulink model is just a constant going to a display box (it will be far more complicated, but this is just for me to sovle this problem). My Simulink model callbacks are:
InitFcn:
TrialApp1
StartFcn:
set(0,'ShowHiddenHandles','on');
blk = 'Trial1/DisplayBox'; % Trial1 is the name of the Simulink model and DisplayBox is what I have named the Display
event = 'PostOutputs';
listener = @(app,event) updateGUI(TrialApp1);
h = add_exec_event_listener(blk,event,listener);
My updateGUI function in App Designer is written as:
methods (Access = public)
function updateGUI(app,varargin)
rto = get_param([bdroot,'/DisplayBox'],'RuntimeObject');
app.EditField.Value = rto.InputPort(1).Data
end
end
I am guessing that the issue lies with how I have my model callbacks written in the Simulink model, but I am really not sure. This format seems to match multiple other places and asnwers that I have found but it seems I have made a mistake somewhere.

답변 (2개)

Justin Coe
Justin Coe 2019년 2월 21일
편집: Justin Coe 2019년 3월 1일
MathWorks contacted me and was able to easily fix my problem, so I will post the solution here for anyone with a similar issiue.
My InitFcn should be written as:
hApp = TrialApp1
Which would then change the listener in my StartFcn to be:
listener = @(app,event) updateGUI(hApp);
That was the only problem. Ther reason is because if you don't define a handle for the app (TrialApp1) then it ends up constructing the app each time. This is in the automatic code created in the grayed section beneath where the user edits are written.
Hopefully my oversight can help someone else in the future if you make the same mistake!
  댓글 수: 2
joao lopes
joao lopes 2019년 11월 12일
Hi, I tried to implement the changes that you said but I can't prevent the simulink from openning multiple GUI's. can you help me?
Should I post the "hApp = TrialApp1" code in InitFcn of the all model or just in the displaybox(in you'r case)?
Gee
Gee 2022년 3월 24일
Thanks, Justin! You are a life saver <3

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


Debraj Bhattacharjee
Debraj Bhattacharjee 2019년 3월 1일
This question has also been answered in a separate MATLAB answers post. The link to this post is given below:

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by