MATLAB: Do I receive an error when I use a data type other than double in the Truth Table in Simulink 6.3 (R14SP3)

stateflow

I receive the following error message when I set the data type of the output of my Truth Table Block to int32 instead of double:
Inferred type (double) for data 'y' (#70) does not match
specified type (int32)

Best Answer

SIMULINK Truth Table blocks use the Embedded MATLAB language subset both for programming conditions and actions, and for generating code. Like other functions based on Embedded MATLAB, Truth Table blocks infer the sizes and types of their outputs from the sizes and types of their inputs. Therefore, the type you specify for an output must match the inferred type or you will receive a type mismatch error.
For example, suppose you specify the type of a truth table output 'y' to be 'int32', but in the truth table action, you add the assignment statement 'y = 0;' In this case, Embedded MATLAB infers the type of 'y' to be 'double' because all values are 'double' by default. The inferred type 'double' does not match the specified type 'int32', causing an error.
To fix type mismatch errors, explicitly cast the value of the output in the assignment statement to match the specified type. In this example, changing the assignment statement to 'y = int32(0);' eliminates the error.