Truth Table Operations

Truth tables implement combinatorial logic design in a concise, tabular format. Truth tables are supported only in Stateflow® blocks in a Simulink® model. For more information, see Reuse Combinatorial Logic by Defining Truth Tables.

To create truth tables, use the Stateflow Editor. You can insert, edit, and move rows and columns. You can also diagnose the truth table for syntax errors and view the auto-generated code for the truth table.

Append Rows and Columns

Append Column adds a column on the right end of the selected table.

Append Row adds a row to the bottom of the selected table.

Diagnose the Truth Table

Run Diagnostics checks the truth table for syntax errors. See Debug Run-Time Errors in a Truth Table.

View Auto-generated Content

View Auto-generated Content displays the code generated for the truth table. C truth tables generate graphical functions. MATLAB® truth tables generate MATLAB code. For details, see View Generated Content for Stateflow Truth Tables.

Edit Tables

The default Condition Table and the default Action Table have one empty row. Click a cell to edit its text contents. To move horizontally between cells, use the up and down arrow keys.

To display only one of the two tables, double-click the header of the table that you want to display. To revert to the display of both tables, double-click the header of the displayed table.

Cells for the numbered rows in decision columns like D1 can take values of T, F, or -. After you select one of these cells, you can use the space bar to step through the T, F, and - values. In these cells you can use the left, right, up, and down arrow keys to advance to another cell in any direction.

Move Rows and Columns

To move a condition or action row up or down:

  1. To select the row, click the row header.

  2. Drag the row to a new position.

    The truth table renumbers the rows.

To move a decision column left or right:

  1. To select the column, click the column header .

  2. Drag the column to a new position.

    The truth table renumbers the decision columns.

Note

To select multiple rows or columns that you want to move, hold down the Ctrl key.

Select and Deselect Table Elements

GoalAction
Select a cell for editingClick the cell
Select text in a cellClick and drag your pointer over the text
Select a rowClick the header for the row
Select a decision column in the Condition TableClick the header for the column
Deselect a selected cell, row, or columnClick outside of the Condition Table or Action Table.

Undo and Redo Edit Operations

To undo the effects of the preceding operation, press Ctrl+Z (Command+Z).

To redo the effects of the preceding operation, press Ctrl+Y (Command+Y).

Zoom

To zoom in on a truth table, press Ctrl++ (Command++).

To zoom out on a truth table, press Ctrl+- (Command+-).

To return to normal view (100%) on a truth table, press Ctrl+0 (Command+0).

View the Stateflow Chart for the Truth Table

To navigate to the Stateflow chart for the truth table, press the Esc key.