Represent logical decision-making behavior with conditions, decisions, and actions
The Truth Table block is a truth table function that uses MATLAB® as the action language. Use this block when you want to use truth table logic directly in a Simulink® model. This block requires a Stateflow license.
When you add a Truth Table block directly to a model instead of calling truth table functions from a Stateflow chart, these advantages apply:
It is a more direct approach, especially if your model requires only a single truth table.
You can define truth table inputs and outputs to have inherited types and sizes.
The Truth Table block works with a subset of the MATLAB language that is optimized for generating embeddable C code. This block generates content as MATLAB code. As a result, you can take advantage of other tools to debug your Truth Table block during simulation.
For purely logical behavior, truth tables are easier to program and maintain than graphical functions. Truth tables also provide diagnostics that indicate whether you have too few (underspecified) or too many (overspecified) decisions for the conditions you specify.
The following model,
shows a home environment controller that attempts to maintain a selected
temperature and humidity. The model has a Truth Table block,
that responds to changes in room temperature (input
and humidity (input
If you double-click the Truth Table block in
the Truth Table Editor opens to display its conditions, actions, and
decisions. Here is the display for the Truth Table block named
the conditions, and the outputs
humidifier define the actions for this Truth
Using the Truth Table Editor, you can:
Enter and edit conditions, actions, and decisions
Add or modify Stateflow data and ports using the Ports and Data Manager
Run diagnostics to detect parser errors
View generated content after simulation
For more information about the Truth Table Editor, see Truth Table Editor Operations.
To add or edit data in a Truth Table block, open the Ports and Data Manager by selecting Add > Edit Data/Ports in the Truth Table Editor.
Using the Ports and Data Manager, you can add these elements to a Truth Table block.
You can add these types of data:
An input trigger causes a Truth Table block to execute when a Simulink control signal changes or through a Simulink block that outputs function-call events. You can use one of these input triggers:
For more information, see Define Events.
|Function-call output||A function-call output triggers a function call to a subsystem. For more information, see Function-Call Subsystems (Simulink) in the Simulink documentation.|
The Truth Table block accepts signals of any data type that Simulink supports, including fixed-point and enumerated data types.
For a discussion of data types that Simulink supports, refer to the Simulink documentation.
For a description of the block parameters, see the Subsystem block reference page in the Simulink documentation.