Getting output data from Simulink
Show older comments
I have a simulink model that runs for 600 time steps and I want to get the output data from the scopes. I set the scope parameters to logging to workspace but when I check my workspace, the output data only has 192 data points. How do I get the values for each time step (getting 600 data points where each point corresponds to a time step).
7 Comments
Mathieu NOE
on 30 Nov 2020
hello
maybe you have a time axis or a buffer size of your scope that limits the display and the "to worksapce" to this limit
why not put beside the scope a specific "to workspace" block and tune the block parameters to get the right amount (and structure) of data
Fangjun Jiang
on 30 Nov 2020
I suspect you have variable time step, so if you have minimum time step as 0.1 and run simulation for 60 seconds, it is not going to be "600 time steps". Log simulation time first to check it out.
Wei Yang Shen
on 30 Nov 2020
Edited: Wei Yang Shen
on 30 Nov 2020
i second the variable timestep notion. if you write the output to a matrix (a different 'sink' block'), the output should be a timeseries equivalent to the data setn to the scope. the time points are determined by the solver and solver settings unless you have some other blocks or signal buffers in there. you've provided no information on those.
Fangjun Jiang
on 30 Nov 2020
Press Ctrl+E, on the left, click "Data Import/Export", on the right, check "Time", select "Array" for "format". Run the simulation, check the value of "tout". How many data points do you have for "tout"?
Wei Yang Shen
on 30 Nov 2020
Fangjun Jiang
on 30 Nov 2020
No need to provide wild guesses like "extra data points are getting truncated" or "it seems it increases by 12 each time". You expect to see 600 data points based on your understanding (which is incorrect). You received 192 data points in one case and 292 data points in another case. This can be explained by the fact that you are using variable time step solver.
You can learn about variable time step solver by right click at "Solver" and select "What's this".
Other than that, there is really no problem. If your simulation results are correct, they are correct.
Answers (1)
Fangjun Jiang
on 1 Dec 2020
1 vote
The different size of the logged data is caused by the variable-step solver. To get a consistent and fixed size log data, use a fixed-step sover.
1 Comment
jessupj
on 1 Dec 2020
i agree: using a fixed timestep solver is the solution here to the OP's problem as stated.
however, it depends on the system. sometimes it's better to interpolate the output of variable timestep solvers to the time points you want; fixed timesteps can be extremely inefficient and/or won't work for stiff problems.
Categories
Find more on Manual Performance Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!