MATLAB Answers

0

App Designer to control a Simulink Model and read back model data

Asked by Justin Mellor on 4 Nov 2016
Latest activity Answered by Rahul Murmude on 13 May 2019 at 14:48
I am trying to create a GUI using App Designer 2016b that will control inputs to the model AND read back model values while the Simulink model is running. I can control the model from an app by including set_param commands in the app callback functions. As per an earlier GUIDE example I have included a callback with the Simulink model that sets up an event listener and calls a Matlab function to update the GUI with the output value of a Gain block. However I do not know how to update the properties of a Gauge in the GUI with the value from the Simulink model. How do I do this? Could someone provide an example please?

  0 Comments

Sign in to comment.

3 Answers

Answer by Chris Portal on 5 Nov 2016

Assuming you have your app running when you want the model to update the Gauge, you could achieve this a couple of ways. In both cases, you'll need a handle to the running app, which is returned as a left hand side argument when you first launch the app, i.e.
hApp = mysimulinkapp;
1) Update the gauge by accessing it directly in your Simulink callback. Assuming the name you gave the gauge in App Designer's Component Browser was "GainGauge", you'd use the syntax:
hApp.GainGauge.Value
2) Alternatively, create a public function in your app that takes care of updating the gauge or any other updating logic you need, and call that function from your Simulink callback. Assuming the public function you create is named "myAppUpdateRoutine", the syntax you'd use to call it is:
myAppUpdateRoutine(hApp, ...)
Hope this helps!

  3 Comments

Thanks for getting back to me on this. I obviously need to launch the app just once, but update the gauge value at each sample time. Is there an easy way to do this? Justin
The steps I described would be the way to do it. Did it not work for you, or are the steps unclear? I'm going by your statement of:
"...I have included a callback with the Simulink model that sets up an event listener and calls a Matlab function to update the GUI..."
In the MATLAB function your listener calls, that is where you would either call:
hApp.GainGauge.Value
or
myAppUpdateRoutine(hApp, ...)
In the first case, where the MATLAB function calls, hApp.GainGauge.Value, if you launch the app in the models startFcn, how do you pass the handle (hApp) to the listener?

Sign in to comment.


Answer by aumit
on 20 Sep 2017

Hi,
I am trying to use this to output the status of my Simulink simulation in an Edit Field in the GUI. Your suggestions do not work for me.
My code in PreLoadFcn is
hApp = Setup;
and in a Matlab function called from Simulink
function guicomm()
happ.StatusEditField.Value = 'Test';
where Setup is the name of my app and StatusEditField the name of the Edit Field. I can see happ in the workspace and if I click on the respective entries I can change the value manually succesfully. If I then try running
happ.StatusEditField.Value = 'Test';
in the Command window, a new structure is created and the original field remains unchanged. If I skip Simulink and enter everything in the Command Window, it works. Do you know what could have gone wrong? Could you please provide a more detailed example? Thanks in advance.

  0 Comments

Sign in to comment.


Answer by Rahul Murmude on 13 May 2019 at 14:48

Can you share the details on how to control the model from an app? I also need to achieve a similar objective. Where I can have a drop down list for giving input parameters to simulink model and then run the model through the app.

  0 Comments

Sign in to comment.