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.
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.
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
while loops, nested
if statements, and
You can call MATLAB functions directly in truth table actions. Also, you can call library
functions (for example, MATLAB
fft functions) and generate code for these
functions by using Simulink
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.
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.
Double-click the truth table.
Open the Property Inspector. In the Modeling tab, under Design, select Property Inspector.
Under the Properties section, select C or MATLAB as the Action Language.
If you do not have the option to change the action language, your truth table is a MATLAB truth table.
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 language||Indices||Expression for not equal to|