MATLAB: How to collect the results from a simulation for the model when I use the SIM command to run the model in Simulink 7.7 (R2011a)

simulink

I am running a Simulink model from a MATLAB script using the SIM command. In my model, I use 'To Workspace' blocks to log the simulation data outputs in the MATLAB workspace. I would like to collect these values from the MATLAB workspace once the simulation is completed.

Best Answer

The results from a simulation when using the SIM command are strored in an object of the class Simulink.Simulationoutputs.
In order to access these values, refer to the code below that can be used to access results from a simple simulation of a model with a 'To Workspace' block.
simOut = sim('vdp_ex', 'StopTime', '10');
workspace_struct = get(simOut, 'simout');
The 'workspace_struct' contains the fields of that are saved from the 'To Workspace' block. In order to access the values in this structure, I execute:
values = workspace_struct.signals.values;
Please execute the lines of code above agiainst the model that is attached to this solutionl.