How do I pass Simulink variables from the “Configuration Parameters” to a GUI created using GUIDE?

11 visualizaciones (últimos 30 días)
I have a GUI created in GUIDE that: 1. Selects a test data CSV file to be simulated from my directory and 2. Allows the user to press “Start” to begin Simulink simulation. The GUI is communicating with Simulink. The Simulink model has a Stateflow model included that is used for trouble shooting control logic. The GUI is implemented to allow someone not familiar with the design of the Simulink/Stateflow model to be able to trouble shoot any test data CSV file easily.
The problem I am having errors with is when pressing the pushbutton “start” in the GUI.fig that is associated with starting the Simulink model. In my GUI.m file for the “start” pushbutton function, I have “sim SimulinkModel” and than also call some plots that compare test data with simulated data. The errors come from the plots, where variables cannot be found, “??? Undefined function or variable 'sim_time'. “.
These variables are defined in the Simulink “Configuration Parameters”, accessed by pressing Ctrl+E while viewing the Simulink model. I am saving, “Save to Workplace”, these variables, i.e. “Time”, “Output”. How do I pass these variables from the Simulink model to the GUI so when I execute the GUI pushbutton “start” I can get the simulation to work? Note, the Simulink simulation works without any error when pressing “Start simulation” from Simulink.
I believe this is something that needs to be added to the GUI.m file for the pushbutton function.
Thank you for the help.

Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 28 de Nov. de 2012
I think the problem might that you are defining the variables (sim_time, etc.) in the function workspace of your GUI, but the Simulink model is looking for them in the base workspace.
To ask Simulink to look in the function workspace, try:
options = simset('SrcWorkspace','current', 'DstWorkspace', 'current');
sim('SimulinkModel', options);
  2 comentarios
Andres
Andres el 28 de Nov. de 2012
Thank you. This worked with a little editing. I changed 'current' to 'base' and also corrected the "sim" line to reflex the newer format:
options = simset('SrcWorkspace','base', 'DstWorkspace', 'base');
sim('SimulinkModel', [], options);

Iniciar sesión para comentar.

Más respuestas (1)

Babak
Babak el 28 de Nov. de 2012
Look up
slConfigUIGetVal
in MATLAB help.

Categorías

Más información sobre Model, Block, and Port Callbacks en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by