How to prevent App Designer GUI from opening multiple GUI figures?
Show older comments
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.
Answers (2)
Justin Coe
on 21 Feb 2019
Edited: Justin Coe
on 1 Mar 2019
1 vote
2 Comments
joao lopes
on 12 Nov 2019
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
on 24 Mar 2022
Thanks, Justin! You are a life saver <3
Debraj Bhattacharjee
on 1 Mar 2019
0 votes
This question has also been answered in a separate MATLAB answers post. The link to this post is given below:
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!