matlab.system.getSampleTime - Query sample time - MATLAB (original) (raw)
Main Content
Syntax
sts = getSampleTime(obj)
Description
[sts](#d126e592855) = getSampleTime([obj](#d126e592821))
returns the sample time specification for the System objectâ„¢ obj
when the System object is included in a MATLAB System block. You can call getSampleTime
in thestepImpl
method to change the algorithm based on the sample time.
Before sample time has propagated throughout the MATLAB System block model,getSampleTime
returns the getSampleTimeImpl sample time specification. If your system object does not override getSampleTimeImpl
, the defaultInherited
sample time specification is returned.
After sample time has propagated, getSampleTime
returns the sample time specification populated with the actual MATLAB System block sample time type, sample time, and offset time.
Input Arguments
System object included in a MATLAB System block that you want to query.
Output Arguments
The sample time specification for the System object. For more details about sample time specification objects, see createSampleTime.
Examples
This example of stepImpl
returns a count value y
, the current simulation time ct
, and the sample time st
. The sample time is obtained by calling getSampleTime
.
function [y,ct,st] = stepImpl(obj,u) y = obj.Count + u; obj.Count = y; ct = getCurrentTime(obj); sts = getSampleTime(obj); st = sts.SampleTime; end
For a complete class definition, see Specify Sample Time for MATLAB System Block System Objects.
Version History
Introduced in R2017b