Skip to Main Content Skip to Search
Product Documentation

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 only MATLAB 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:

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 more information, see Debugging a MATLAB Function in a Chart.

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. For an introduction to truth tables, see Truth Table Functions for Decision-Making Logic.

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. For more details, refer to the demo description for this model.

Using the Truth Table Editor, you can:

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 Defining Events.

Function-call output A function-call output triggers a function call to a subsystem. For more information, see Function-Call Subsystems 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 Working with 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

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS