How to access time step in simulink model?

조회 수: 298 (최근 30일)
GD
GD 2015년 8월 25일
답변: Jeff Chang 2022년 3월 27일
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?

답변 (3개)

Jeff Chang
Jeff Chang 2022년 3월 27일
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 2015년 8월 26일
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 2021년 5월 25일
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.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by