Documentation Center

  • Trial Software
  • Product Updates

Truth Table

Represent logical decision-making behavior with conditions, decisions, and actions

Library

Stateflow®

Description

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, sf_climate_control, shows a home environment controller that attempts to maintain a selected temperature and humidity. The model has a Truth Table block, ClimateController, that responds to changes in room temperature (input t) and humidity (input h).

Truth Table Editor

If you double-click the Truth Table block in sf_climate_control, the Truth Table Editor opens to display its conditions, actions, and decisions. Here is the display for the Truth Table block named ClimateController.

The inputs t and h define the conditions, and the outputs heater, cooler, and humidifier define the actions for this Truth Table block.

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.

Ports and Data Manager

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.

ElementToolDescription
Data

You can add these types of data:

  • Local

  • Constant

  • Parameter

  • Data store memory

Input trigger

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:

  • Rising edge

  • Falling edge

  • Either rising or falling edge

  • Function call

For more information, see Define Events.

Function-call output A function-call output triggers a function call to a subsystem. For more information, see Create a Function-Call Subsystem in the Simulink documentation.

Data Type Support

The Truth Table block accepts signals of any data type that Simulink supports, including fixed-point and enumerated data types. The block also accepts frame-based signals. Truth Table blocks work with frame-based signals in the same way as MATLAB Function blocks (see Add Frame-Based Signals in the Simulink documentation).

For a discussion of data types that Simulink supports, refer to the Simulink documentation.

Parameters and Dialog Box

For a description of the block parameters, see the Subsystem block reference page in the Simulink documentation.

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

N/A

Dimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?