How to access time step in simulink model?

291 vues (au cours des 30 derniers jours)
GD
GD le 25 Août 2015
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?

Réponses (3)

Jeff Chang
Jeff Chang le 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 le 26 Août 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 le 25 Mai 2021
You can access the step size from the model configuration parameters using the command:
get_param(bdroot,'FixedStep')
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.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by