Access app designer variables in Simulink

11 views (last 30 days)
RW Student
RW Student on 16 Jan 2019
Commented: Amanda Quan on 2 Apr 2021
Hi there,
I am trying to make an interface around a simulink simulation using app designer. An user should be able to input values for certain parameters. When he/she clicks "Simulate", the application should simulate the Simulink model with the given parameters. The application and simulink file are in the same folder. I used the code below to set parameters and simulate the model. However, I get the error 'Undefined function or variable [...] Variable does not exist'. In other words, the Simulink model cannot access the variables created in the app designer. Any suggestions? FYI: running the Simulink file from a Matlab script works fine.
Variable1 = app.Variable1.Value;
Variable2 = app.Variable2.Value;
simOut = sim('simulinkFile','ReturnWorkspaceOutputs','on');
  2 Comments
Amanda Quan
Amanda Quan on 2 Apr 2021
"Under the callback function for your run simulation button"
Can you help me out on where this is? I have a function that executes when my Start/Stop button is pushed, but that's not where I'm interfacing callbacks (I don't think) - the callbacks are listed out within my function which creates the SimulationInput object. Which of those two areas (or another one entirely) is "under the callback function for my run simulation button"?
(Caveat I'm an extreme newbie and got most of my code from the Mathworks LorenzSystemApp example, but they use set_param to set the variables within their Simulink model and for whatever reason that isn't working for me so I'm looking for alternatives.)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!