matlab.System - how do I get the actual timestep size

조회 수: 3 (최근 30일)
Pier-Yves Lessard
Pier-Yves Lessard 2022년 1월 24일
답변: Prateekshya 2023년 9월 28일
I am using the matlab.System class to implement a block that requires to know the timestep (in seconds) for integration in the stepImpl method.
I could find 2 ways of getting something close to what I want.
  1. Use getCurrentTime() and make a diff with previous step. Drawback : first step is always 0.
  2. Inject the timestep from Simulink using the "Weighted Sample Time" block and add a input to my stepImpl method.
Is there a better way to do this? Ideally, I could query the same value given by the wieghted sample time block, without having to add an input for it.
Regards

답변 (1개)

Prateekshya
Prateekshya 2023년 9월 28일
Hi Pier-Yves,
As per my understanding you want to know about an optimal way that can be used to find out the time step. You can use "getSampleTime" method provided by "matlab.System" class to retrieve the sample time information including the time step. Here is a small example:
sampleTime = obj.getSampleTime(); % obj is the System object
timestep = sampleTime.SampleTime; % SampleTime is a property
You can replace the "SampleTime" property with the property that you want. You can find the list of properties in this link: https://in.mathworks.com/help/matlab/ref/matlab.system.createsampletime.html#namevaluepairs
For more information on "getSampleTime" method you can follow this link: https://in.mathworks.com/help/matlab/ref/matlab.system.getsampletime.html
I hope it helps!

카테고리

Help CenterFile Exchange에서 Create System Objects에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by