Getting output data from Simulink

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

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
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
Wei Yang Shen on 30 Nov 2020
Edited: Wei Yang Shen on 30 Nov 2020
I have a feeling that the issue is not because the extra data points are getting truncated but rather that all the data points are being averaged in a way so that it fits a smaller size (600 points are being averaged so that it can be represented as 192 points). The output graph that the scope displays is correct and has all the points.
jessupj
jessupj on 30 Nov 2020
Edited: jessupj 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.
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"?
It seems that I get 292 points from 0 to 600 and it seems it increases by 12 each time except the 2 and 3 values which do not seem to follow this pattern. To reply to jessupj, this was originally a script that called ode45 on a matlab function so when I converted it to simulink I just used a matlab function block. I also have demultiplexers to break up the output matricies into individual scopes.
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.

Sign in to comment.

Answers (1)

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

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.

Sign in to comment.

Categories

Products

Release

R2020a

Asked:

on 29 Nov 2020

Commented:

on 1 Dec 2020

Community Treasure Hunt

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

Start Hunting!