createSampleTime

Class: matlab.system.mixin.SampleTime

Create sample time specification object

Syntax

sts = createSampleTime(obj)
sts = createSampleTime(obj,'Type',Type)
sts = createSampleTime(obj,'Type',Type,Name,Value)

Description

sts = createSampleTime(obj) creates a sample time specification object for inherited sample time for the System object™ obj. Use this sample time specification object in the getSampleTimeImpl method of your System object. The sample time specification affects the simulation time when the System object is included in a MATLAB System block.

sts = createSampleTime(obj,'Type',Type) creates a sample time specification object with the specified sample time type.

sts = createSampleTime(obj,'Type',Type,Name,Value) creates a sample time specification object with additional options specified by one or more Name,Value pair arguments. Name is a property name and Value is the corresponding value. Name must appear inside single quotes (''). You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Input Arguments

expand all

System object that you want to specify the sample time.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Type','Fixed In Minor Step'

Type of sample time you want the System object to use in Simulink®. For descriptions of the different types of sample times, see:

Example: createSampleTime('Type','Fixed In Minor Step')

Optional for Inherited sample time only.

When the sample time type is set to Inherited, this option disallows inherited controllable sample time. Use this option if your System object depends on having constant time between each sample-time hit.

If controllable sample time is propagated to the System object, discrete sample time is used instead with the same tick time as the propagated controllable sample time.

Example: createSampleTime('Type','Inherited','Disallow','Controllable')

For Discrete sample time only.

Specify the time between sample hits in Simulink.

Example: createSampleTime('Type','Discrete','SampleTime',1)

Data Types: single | double

For Discrete sample time only.

Specify the offset time for the sample hit. The offset is a time interval indicating an update delay. The block is updated later in the sample interval than other blocks operating at the same sample rate.

The offset time must be nonnegative and less than SampleTime.

Example: createSampleTime('Type','Discrete','SampleTime',2,'OffsetTime',1)

Data Types: single | double

Required for Controllable sample time only.

Specify the time between controllable sample time hits. The tick time must be a positive scalar.

Example: createSampleTime('Type','Controllable','TickTime',obj.TickTime)

Data Types: single | double

Output Arguments

expand all

The sample time specification object. This object has the following properties:

Use this object as the return value of getSampleTimeImpl.

Examples

expand all

Specify that the MATLAB System block inherits the sample from upstream blocks. Inherited sample time is the default, so no additional arguments are needed.

function sts = getSampleTimeImpl(obj)
    sts = createSampleTime(obj);
end

Specify a discrete sample time specification for the MATLAB System block, including offset time and the sample time.

function sts = getSampleTimeImpl(obj)
    sts = createSampleTime(obj,'Type','Discrete',...
      'SampleTime',10.2,'OffsetTime',0.5);
end

Introduced in R2017b