Main Content

Specify Sample Time for MATLAB System Block

The sample time of a block is a parameter that indicates when the block produces an output, and eventually updates its internal state. To specify sample time for MATLAB® System block, implement the getSampleTimeImpl method with a call to createSampleTime. To query the MATLAB System block for current sample time and simulation time, use the getSampleTime and getCurrentTime methods. For more information, see Specify Sample Time for MATLAB System Block System Objects.

Types of Sample Time for MATLAB System Block

If you use discrete sample time in simulation, Simulink® only calculates the output of a simulation for each of the fixed time intervals. To specify discrete sample time, in the createSampleTime, set 'Type' to 'Discrete' and set the 'SampleTime' property.

When the sample time is inherited, Simulink determines the best sample time for the block based on the block's role within the model. To specify inherited sample time, in the createSampleTime, set 'Type' to 'Inherited'. When using inherited sample time, you can alter or error out on specific sample times by specifying the 'AlternatePropagation' or 'ErrorOnPropagation' Name-Value pair.

In fixed-in-minor-step sample time, Simulink does not execute the block at the minor time steps, the updates only occur at the major time steps. To specify the fixed-in-minor time step, in the createSampleTime, set 'Type' to 'Fixed In Minor Step'.

To use controllable sample time, configure a block to specify controllable sample time with a resolution Tbase, where Tbase is the smallest allowable time interval between block executions. A block using controllable sample time can be dynamically set to execute at n multiples of Tbase, then the block's next execution is

Tnext = n Tbase + T

To specify Tbase in MATLAB System block, in the createSampleTime, set 'Type' to 'Controllable' and set the 'TickTime' property to Tbase. You can set the n in your MATLAB System block using setNumTicksUntilNextHit.

For more information on types of sample time, see Types of Sample Time. To see an example on how to control the sample time of the MATLAB System block using System object™ methods, see Specify Sample Time for MATLAB System Block System Objects.

See Also

| | | |

Related Topics

Related Topics