Language Options for Stateflow Truth Tables

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.

C Truth Tables

Using C truth tables, you can specify conditions and actions with C as the action language. C truth tables support basic C constructs and provide access to MATLAB® functions by using the ml namespace operator or ml function. To use C as the action language for your truth table, it must be inside a Stateflow C action language chart.

MATLAB Truth Tables

Truth Table blocks and truth tables inside charts that use MATLAB as the action language are MATLAB truth tables. In these MATLAB truth tables, you cannot specify C as the action language. You can specify conditions and actions in MATLAB truth tables, which provides optimizations for simulation and code generation.

MATLAB truth tables offer several advantages over C truth tables:

  • MATLAB as the action language provides a richer syntax for specifying control flow logic in truth table actions. It provides for loops, while loops, nested if statements, and switch statements.

  • You can call MATLAB functions directly in truth table actions. Also, you can call library functions (for example, MATLAB sin and fft functions) and generate code for these functions by using Simulink Coder™software.

  • You can create temporary or persistent variables during simulation or in code directly without having to define them in the Model Explorer.

  • You have access to better debugging tools. You can set breakpoints on lines of code, step through code, and watch data values tool tips.

  • You can use persistent variables in truth table actions. You can define data that persists across multiple calls to the truth table function during simulation.

Select a Language for Stateflow Truth Tables

If the truth table is inside a C action language Stateflow chart, you can specify an action language for your Stateflow truth table by using the Property Inspector.

  1. Double-click the truth table.

  2. Open the Property Inspector. In the Modeling tab, under Design, select Property Inspector.

  3. Under the Properties section, select C or MATLAB as the Action Language.

Note

If you do not have the option to change the action language, your truth table is a MATLAB truth table.

Migration from C to MATLAB Truth Tables

When you migrate from a C truth table to a MATLAB truth table, you must verify that the code to program the actions conforms to MATLAB syntax. Between the two action languages, these differences exist.

Action languageIndices Expression for not equal to
MATLAB One-based~=
CZero-based!=