Main Content


Query sample time


sts = getSampleTime(obj)


sts = getSampleTime(obj) 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 the stepImpl 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 default Inherited 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

expand all

System object included in a MATLAB System block that you want to query.

Output Arguments

expand all

The sample time specification for the System object. For more details about sample time specification objects, see createSampleTime.


expand all

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;

For a complete class definition, see Specify Sample Time for MATLAB System Block System Objects.

Version History

Introduced in R2017b