How can I get the data from my To Workspace block into the MATLAB workspace when using the SIM command in a MATLAB function in Simulink 6.2 (R14SP2)?

23 views (last 30 days)
I simulate my Simulink model using the SIM command from a MATLAB function or a GUI created using GUIDE. The To Workspace block in the model does not send the data out to the workspace. If I run the same model from Simulink, the command-line or from a MATLAB script, the To Workspace block does return data to the MATLAB workspace.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Jan 2010
This enhancement has been incorporated in Release 2009b (R2009b). For previous product releases, read below for any possible workarounds:
The SIM command simulates the model in the caller workspace that is any output from the model is sent to the caller workspace and not to the base workspace. To work around this you can use the EVALIN command in your MATLAB function or GUI callback where the SIM command is being called.
1. Download the attached files and execute the following code at MATLAB command prompt:
mini_gui
2. Click on the "simulate model" button in the GUI displayed. Verify that "simout" exists in the MATLAB base workspace by typing the following at MATLAB command prompt:
whos
The "mini_gui.m" file uses the following code to import the data to MATLAB base workspace.
evalin('base','sim(''mini_model'')')
Also, note that the SIM command takes the values required for simulation from the base workspace. Refer to the Related Solution below for an example that demonstrates this.

More Answers (0)

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!