MATLAB: Can’t I use an Enumerated data type inherited from int32 as a logical value in an IF statement when generating code using MATLAB Coder 2.2 (R2012a)

enumeratedifinheritint32matlab coderstatement

I have defined an enumeration type for "Boolean", subclassed from 'int32' as shown in the Code Generation documentation examples.
classdef Boolean < int32
enumeration
False(0)
True(1)
end
end
The MATLAB code I have written to utilize this class has the following IF statement:
x = Boolean.True;
if x
...
end
When I try to build the Coder project, I get the following error:
??? Expected either a logical, char, int, single, double or fi that can represent zero. Found a Boolean.
This works fine with the following statements:
if int32(x)
...
end
if x == 1
...
end
if x == Boolean.True
...
end
If the Boolean class inherits the int32 class, why does my original code not generate correctly with MATLAB Coder 2.2 (R2012a)?

Best Answer

This is expected behavior of enumerated classes inherited from the int32 data type in MATLAB Coder 2.2 (R2012a). Implicit casting to int32 is not observed in IF statements.
As a workaround, please use one of the three alternatives listed above in your MATLAB file.