How to access time step in simulink model?

265 visualizaciones (últimos 30 días)
GD
GD el 25 de Ag. de 2015
Respondida: Jeff Chang el 27 de Mzo. de 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?

Respuestas (3)

Jeff Chang
Jeff Chang el 27 de Mzo. de 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 el 26 de Ag. de 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 el 25 de Mayo de 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.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by