How to access time step in simulink model?

294 views (last 30 days)
GD on 25 Aug 2015
Answered: Jeff Chang on 27 Mar 2022
I want to make a Matlab function in simulink model. In this function I want to calculate relative acceleration between two cars,but to do this I will need to divide the relative velocity with time step. How could i do this?

Answers (3)

Jeff Chang
Jeff Chang on 27 Mar 2022
I use the following loop to calculate variable-step time step differences
The memory block will store and output the previous time stamp and the subtract block will subtract current time from previous time to output time difference.
For example, I have a 1DoF rocket launch simulator, which outputs height, velocity and acceleration on the left, and the time step taken to calculate the output is plotted on the graph on the right indicating I'm using a variable step calculator at the time.

Sebastian Castro
Sebastian Castro on 26 Aug 2015
I wouldn't really recommend using MATLAB Function blocks to approximate derivatives, given that Simulink blocks have much better support for time-based integration...
My unsolicited preaching aside: If you want to pass in the simulation time into the MATLAB Function block, you could use a Clock from the Simulink > Sources library.
- Sebastian

Aseem Routray
Aseem Routray on 25 May 2021
You can access the step size from the model configuration parameters using the command:
This should work if the solver settings have been chosen as a fixed step solver. You can right click on any parameter in the configuration parameters and then click on 'What's This?' to get the command line for setting the parameter using matlab commands.

Community Treasure Hunt

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

Start Hunting!

Translated by