Why do I get an error while trying to compare two numbers of FIXDT data type in my Embedded Matlab Block comparison operator in Simulink 7.3 (R2009a)?

4 views (last 30 days)
I am comparing two fixed point signals inside of an Embedded MATLAB Block, one of type fixdt(0,9,0), and one of type fixdt(0,7,0), as below:
function y = fcn(u1,u2)
%#eml
if u1>u2
y = 1;
else
y=0;
end
However, if I change either one to data type fixdt(0,8,0), Simulink changes the data type to a uint8 (not a ufix8), and the Embedded MATLAB block cannot perform the operation. I get the following error:
In fi > non-fi, the non-fi must be a constant.
Function 'Embedded MATLAB Function1' (#104.33.38), line 3, column 4:
"u1>u2"

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is expected behavior. To get the Embedded MATLAB block to recognize this signal as an FI object, please perform the following steps:
There is drop-down menu in the EML Ports and Data Manager that says "Treat these inherited Simulink signal types as fi objects" - select "Fixed-point & integer" for this parameter.
Similarly:
fixdt(1,8,0) -> int8
fixdt(0,16,0) -> uint16
fixdt(1,16,0) -> int16
fixdt(0,32,0) -> uint32
fixdt(1,32,0) -> int32
fixdt(0,64,0) -> uint64 AND
fixdt(1,64,0) -> int64
If your wordlength is not 8,16,32 or 64 (when fraction length is 0), only then is the type treated as a non-builtin fixed-point type.
Alternately, you can use the following comparison in your EML code:
if u1 > fi(u2,0,8,0)

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!