View Sample Time Information
Simulink® models can display color coding and annotations that represent specific sample times. You can display the blocks and signal lines in color. The annotations are badges on the output ports on the blocks and are colored in black:
To enable colors, in the Simulink model window, on the Debug tab, select Information Overlays > Colors.
To enable annotations, on the Debug tab, select Information Overlays > Text.
Selecting both Colors and Text displays both the colors and the annotations. Regardless of your choice, Simulink performs an Update Model automatically.
To turn off the colors and annotations:
On the Debug tab, select Information Overlays > Colors to disable colors.
On the Debug tab, select Information Overlays > Text to disable annotations.
When you change these settings, the software automatically performs Update Diagram.
Your sample time display choices directly control the information that the Timing Legend displays.
Note
The discrete sample times in the table Designations of Sample Time Information represent a special case. Five colors indicate the speed through the fifth fastest discrete rate. A sixth color, orange, represents all rates that are slower than the fifth discrete rate. You can distinguish between these slower rates by looking at the annotations on their respective signal lines.
Inspect Sample Time Using Timing Legend
You can view the Timing Legend for an individual model or for multiple models. Additionally, you can prevent the legend from automatically opening when you select options on the Sample Time menu.
To assist you with interpreting a block diagram, the Timing Legend contains the sample time color, annotation, and value for each sample time in the model. To view the legend:
In the Simulink model window, on the Modeling tab, click Update Model.
On the Debug tab, select Information Overlays > Legend, or press Ctrl+J.
You can also use the shortcut on the Explorer Bar on the left side of the Simulink Editor.
In addition, when you select Colors or Text, the software updates the model diagram and opens the legend by default. The legend contents reflect your choices. If you turn colors on, the legend displays the color and the value of the sample time. If you turn annotations on, the annotations appear in the legend.
The legend displays sample times present in the model, classified by the type of the sample time. To avoid clutter, the timing information is displayed in rows that expand to show more information about each specific sample time. You can expand each row to learn how that specific sample time is introduced in the model. Check boxes for sample times also allow you to choose specific sample times to display. The Timing Legend also displays the base rate and scalar multipliers for analysis of the discrete time-lines.
For discrete sample time, the Time/Freq toggle button allows you to choose the format of the multiplier information. All discrete sample times are combined into the same row, for example, periodic partitions, discrete export function etc. Triggered sample time rates are now visualized as their source sample times, illustrating the sample rate that drives the trigger. Annotations for aperiodic partition, reset, initialize, reinitialize, and terminate sample times do not use their event names as annotations but instead have their own concise annotations.
The Timing Legend allows you to highlight the blocks and signals in the model that the sample time originates from. Expand a sample time row, and then click the hyperlink of the block, to see where the block is present in the model.
Note
The Timing Legend displays all of the sample times in the model, including those that are not associated with any block. For example, if the fixed step size is 0.1 and all of the blocks have a sample time of 0.2, then both rates (0.1 and 0.2) appear in the legend.
Starting in R2023b, you do not need to update the diagram for your model when changing the sample time visualization options or when launching the Timing Legend after model compilation.
If you do not want to view the legend upon selecting Sample Time Display:
In the Simulink Editor, on the Modeling tab, select Environment > Simulink Preferences
In the General pane, clear Open the timing legend when the sample time display is changed and click Apply.
Inspect Sample Times Throughout a Model
The Model Data Editor shows information about model data such as signals,
parameters, and states, in a sortable, searchable table. To open the Model Data
Editor, on the Modeling tab, click Model Data
Editor.The Sample Time column shows the sample
time specified for each signal in a model. After you update the block diagram, the
column also shows the specific sample that each signal uses. For example, for
signals for which you specify inherited sample time, the column shows
-1
. You can also use this column to specify sample times.
For more information, see Model Data Editor.
Customize Sample Time Colors
You can customize sample time color palette using the simulink.sampletimecolors.Palette
object and its functions. You can
create a customized color palette object for all types of sample times in your
model. You can then use this palette object for your current MATLAB® session, or make it a default color palette for all your MATLAB sessions.
Create a Custom Color Palette for Sample Times and Use it as Default
Create a custom color palette object with the name
myFirstPalette
pltObj = simulink.sampletimecolors.Palette("myFirstPalette")
Palette with properties: Name: "myFirstPalette" ContinuousSampleTimeColors: [0 0 0] FixedInMinorStepSampleTimeColors: [0.4902 0.4902 0.4902] ContinuousVariableSampleTimeColors: [0.4902 0.4902 0.4902] DiscreteSampleTimeColors: [3x3 double] AsynchronousSampleTimeColors: [0.7529 0.3608 0.9843] AperiodicPartitionColors: [0.7529 0.3608 0.9843] InitializeEventSampleTimeColors: [0.7961 0.5176 0.3647] TerminateEventSampleTimeColors: [0.7961 0.5176 0.3647] ResetEventSampleTimeColors: [0.7961 0.5176 0.3647] ReinitializeEventSampleTimeColors: [0.7961 0.5176 0.3647] ConstantSampleTimeColors: [0.8196 0.0157 0.5451] MultirateSampleTimeColors: [0.5451 0.4000 0.0235] UnionSampleTimeColors: [0.4039 0.2980 0.0235]
Customize colors for the discrete sample time using RGB values.
pltObj.ContinuousSampleTimeColors = [0.9 0.2 0.4];
Customize colors for continuous sample time using hexadecimal codes
pltObj.DiscreteSampleTimeColors = ["#123456", "#523467", "#204973"]
Set the new custom color palette as a default palette for the current MATLAB session.
To see the new color palette for sample times in your Simulink model, update the model diagram with Ctrl+D.simulink.sampletimecolors.applyPalette(pltObj)
See Also
simulink.sampletimecolors.applyPalette
| simulink.sampletimecolors.Palette
| simulink.sampletimecolors.getPalette
| simulink.sampletimecolors.removePalette
| simulink.sampletimecolors.storePalette