How do I pass Simulink variables from the “Configuration Parameters” to a GUI created using GUIDE?
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Kaustubha Govind
on 28 Nov 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 Comments
More Answers (1)
See Also
Categories
Find more on Naming Conventions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!