Simulink SimulationOutput aaccess via Code

1 view (last 30 days)
Jakob Mohr
Jakob Mohr on 12 Oct 2021
Answered: Chetan Bhavsar on 12 Oct 2021
Hi,
in my recent tries of working with Simulink i've encountered a problem with the Block "ToWorkspace" or also known as "SimOut". The Data i am getting is just written in the "ans" variable after the Simulation and cannot be accessed by:
temp = Simulink.SimulationOutput;
either before or after the simulation start with:
sim(modelname)
Is the only way to access the whole structure by the following code?:
sim(modelname)
temp = ans;
Many Thanks
JM

Answers (1)

Chetan Bhavsar
Chetan Bhavsar on 12 Oct 2021
load_system('sampleModel');
[T] = sim('sampleModel');
Warning: The file containing block diagram 'sampleModel' has been changed on disk since it was loaded. Simulink is unable to reload it automatically because it is the root model. Close it and reopen it manually.
T
T =
Simulink.SimulationOutput: simout1: [1x1 timeseries] simout2: [1x1 timeseries] tout: [51x1 double] yout: [1x1 Simulink.SimulationData.Dataset] SimulationMetadata: [1x1 Simulink.SimulationMetadata] ErrorMessage: [0x0 char]
T.simout1
timeseries Common Properties: Name: '' Time: [51x1 double] TimeInfo: tsdata.timemetadata Data: [51x1 double] DataInfo: tsdata.datametadata
T.simout1.Data
ans = 51×1
0 0.0998 0.1987 0.2955 0.3894 0.4794 0.5646 0.6442 0.7174 0.7833

Community Treasure Hunt

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

Start Hunting!