Sharing Variables between AppDesigner and Simulink

13 views (last 30 days)
I have a code environment which consists of a Matlab AppDesigner app, a Simulink model and a few Matlab Script functions. The workflow is as follows:
  1. The user defines input values and simulation options in the AppDesigner's GUI, and starts the simulation by pressing a button;
  2. These variables are exported to Matlab's Workspace using the "assignin" function;
  3. The Simulink model is programatically executed with a Script;
  4. The outputs of the Simulink model are exported back to Matlab's workspace;
  5. The Script functions perform post-processing calculations on the Simulink outputs;
  6. The results are imported back to the AppDesigner GUI using the "evalin" function to be plotted for the user to see them.
Is there a simpler or more organized way to do this communication between Matlab, Simulink and AppDesigner? Is it better to not use AppDesigner altogether?
Also, is it possible to export the variables from AppDesigner as fields of a Struct to have a more organized workspace? The number of variables is very large.

Answers (1)

Adarsh
Adarsh on 2 May 2025
I understand that you are trying to create a GUI to take input data and parameters from user to run a Simulink model and plot the results using the App designer.
From what I found “App designer” has built in support for Simulink components integration. In the “Component Library” you will find a section named “Simulink” where you can find components like “Load Input Button”, “Save Output Button”, “Simulation Controls Button” and “Variable Tuner Button” and “Time Scope Button”.
With the help of these components, you can easily perform the required tasks.
Here is the detailed workflow:
  1. Add “Load Input” component and bind it to the Simulink model required.
  2. Add “Simulation Controls” component to the app.
  3. Add “Variable Tuner” to directly modify the tunable variables before simulation.
  4. Add “Time Scope” and bind it to a signal by right clicking it and select “Add Binding” option, for the “Time Scope” to bind to the signal, logging must be activated for that signal.
I have attached the app, and the model files used for your reference.
If you want to have greater control over the model, you can do this programmatically as well for that you can refer to that following MATLAB Answers:
  1. https://www.mathworks.com/matlabcentral/answers/446302-how-do-i-update-a-gui-designed-in-app-designer-with-data-from-a-running-simulink-model
  2. https://www.mathworks.com/matlabcentral/answers/520608-how-can-i-pass-parameters-from-app-designer-to-simulink
  3. https://www.mathworks.com/matlabcentral/answers/310658-app-designer-to-control-a-simulink-model-and-read-back-model-data
For more information you can refer to the following documentation link:
Hope this helps.

Categories

Find more on Large-Scale Modeling in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!