| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Simulink allows you to specify a block sample time directly as a numerical value or symbolically by defining a sample time vector. In the case of a discrete sample time, the vector is [Ts, To] where Ts is the sampling period and To is the initial time offset. For example, consider a discrete model that produces its outputs every two seconds. If your base time unit is seconds, you can directly set the discrete sample time by specifying the numerical value of 2 as the SampleTime parameter. Because the offset value is zero, you do not need to specify it; however, you can enter [2,0] in the Sample time field.
For nondiscrete blocks, the components of the vector are symbolic values that represent one of the types in Types of Sample Time. The following table summarizes these types and the corresponding sample time values. The table also defines the explicit nature of each sample time type and designates the associated color and annotation. Because an inherited sample time is explicit, you can specify it as [-1, 0] or as -1. Whereas, a triggered sample time is implicit; only Simulink can assign the sample time of [-1, -1]. (For more information about colors and annotations, see How to View Sample Time Information.)
Designations of Sample Time Information
| Sample Time Type | Sample Time | Color | Annotation | Explicit |
|---|---|---|---|---|
| Discrete | [Ts, To] | red, green, blue, light blue, dark green, orange | D1, D2, D3, D4, D5, D6, D7,... Di | Yes |
| Continuous | [0, 0] | black | Cont | Yes |
| Fixed in minor step | [0, 1] | gray | FiM | Yes |
| Inherited | [–1, 0] | N/A | N/A | Yes |
| Constant | [Inf, 0] | magenta | Inf | Yes |
| Variable | [–2,Tvo] | brown | V1, V2,... Vi | No |
| Hybrid | N/A | yellow | N/A | No |
| Triggered | [–1, –1] | cyan | T | No |
| Asynchronous | [–1, –n] | purple | A1, A2,... Ai | No |
You can use the explicit sample time values in this table to specify sample times interactively or programmatically for either block-based or port-based sample times. The following model, Specify_Sample_Time.mdl, serves as a reference for this section.
Specify_Sample_Time.mdl

In this example, our goal is to set the sample time of the input sine wave signal to 0.1 and to achieve an output sample time of 0.2. The Rate Transition block serves as a zero-order hold. The resulting block diagram after setting the sample times and simulating the model is shown in the following figure. (The colors and annotations indicate that this is a discrete model.)
Specify_Sample_Time.mdl after Setting Sample Times

To set the sample time of a block interactively:
In the Simulink model window, double-click the block. The block parameter dialog box opens.
Enter the sample time in the Sample time field.
Click OK.
Following is a figure of a parameters dialog box for the Sine Wave block after entering 0.1 in the Sample time field.

The Rate Transition block has port-based sample times. You can set the output port sample time interactively by completing the following steps:
Double-click the Rate Transition block. The parameters dialog box opens.
Leave the drop-down menu choice of the Output port sample time options as Specify.
Replace the -1 in the Sample time field with 0.2.

Click OK.
For more information about the sample time options in the Rate Transition parameters dialog box, see the Rate Transition reference page.
To set a block sample time programmatically, set its SampleTime parameter to the desired sample time using the set_param command. For example, to set the sample time of the Gain block in the "Specify_Sample_Time" model to inherited (-1), enter the following command:
set_param('Specify_Sample_Time/Gain','SampleTime','[-1, 0]')As with interactive specification, you can enter just the first vector component if the second component is zero.
set_param('Specify_Sample_Time/Gain','SampleTime','-1')To set the output port sample time of the Rate Transition block to 0.2, use the set_param command with the parameter OutPortSampleTime:
set_param('Specify_Sample_Time/Rate Transition',...
'OutPortSampleTime', '0.2')To access all sample times associated with a model, use the API Simulink.BlockDiagram.getSampleTimes.
To access the sample time of a single block, use the API Simulink.Block.getSampleTimes.
You can design custom blocks so that the input and output ports operate at different sample time rates. For information on specifying block-based and port-based sample times for S-functions, see Sample Times .
Since the execution of a Simulink model is not dependent on a specific set of units, you must determine the appropriate base time unit for your application and set the sample time values accordingly. For example, if your base time unit is second, then you would represent a sample time of 0.5 second by setting the sample time to 0.5.
To change a sample time after simulation begins, you must stop the simulation, reset the SampleTime parameter, and then restart execution.
![]() | What Is Sample Time? | How to View Sample Time Information | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |