Main Content

createSampleTime

Class: matlab.System

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. If you do not include this method in your System object definition, the sample time is inherited.

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 quotes. You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Dependencies

You can only call createSampleTime from the getSampleTimeImpl method of your System object.

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')

For Inherited sample time only.

Specify one or more sample times you want to allow your object to use. When the sample time type is set to Inherited and the MATLAB System block receives the specified sample time, the block allows the sample time to propagate. You can specify multiple sample time types as a cell array or string array.

Example: createSampleTime('Type','Inherited','AllowPropagation',{'Controllable','Continuous'})

For Inherited sample time only.

Specify one or more sample times you do not want your object to use. When the sample time type is set to Inherited and you do not want the MATLAB System block to use the specified inherited sample time type, an alternative sample time is used by the block instead. You can specify multiple sample time types. For each sample time type, Simulink substitutes a different sample time type:

  • 'Controllable' — The base rate of the controlled sample is propagated instead. Use this option if your System object depends on having constant time between each sample-time hit.

  • 'Constant' — The base rate of the model is propagated instead, either the fastest discrete rate or fixed in minor step.

  • 'Continuous' — The fastest discrete rate is propagated instead.

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

For Inherited sample time only.

Specify one or more sample times you do not want your object to use. When the sample time type is set to Inherited and the MATLAB System block receives the specified sample time, Simulink throws an error.

Example: createSampleTime('Type','Inherited','ErrorOnPropagation','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