MATLAB: Does the boolean cast for Stateflow not output a 1 or 0

booleancastingdatatypestateflowtype

For my transition, I have the following:
{y1 = boolean(x1);
y2 = boolean(x2);
y3 = (y1 == y2);}
If x1 = 2 and x2 = 3, Stateflow outputs y1 = 2 and y2 = 3. I expect y1 = 1 and y2 = 1.

Best Answer

This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
We have verified that there is a bug in Stateflow in the way it handles boolean type casting. Currently, Stateflow is type casting a boolean datatype as an unsigned int datatype which is what a boolean datatype is defined as in tmwtypes.h. The boolean cast for Stateflow should be doing a "!=0".
To work around this issue, try adding "!=0". For example,
{
y1 = boolean(x1!=0);
y2 = boolean(x2!=0);
y3 = (y1 == y2);
}
Related Question