fiaccel set fi numeric type based on input
Show older comments
I have stumble across an issue that doesnt allow "flexible" coding, and I am trying to find ways to work around it. I got the following script as example example_fi.m.
function [outputArg1] = example_fi(M)
U2_0 = numerictype(0, 2, 0);
U3_0 = numerictype(0, 3, 0);
U4_0 = numerictype(0, 4, 0);
if M == 2
outputArg1 = fi(0, U2_0, 'RoundingMethod', 'Floor', 'OverflowAction', 'Saturate');
elseif M == 3
outputArg1 = fi(0, U3_0, 'RoundingMethod', 'Floor', 'OverflowAction', 'Saturate');
else
outputArg1 = fi(0, U4_0, 'RoundingMethod', 'Floor', 'OverflowAction', 'Saturate');
end
end
Trying to convert it to a mex using following,
fiaccel example_fi -args {coder.typeof(0, 1,1)} -o example_fi_mex
I get this error: ??? Type mismatch: embedded.fi {ufix2} ~= embedded.fi {ufix3}.
It looks like fiaccel doesnt like initialise the same variable under different numeric types. I also tried using switch instead of if, but I get the same error.
Is there a way to work around this or simply always intialise with the highest numeric type?
Accepted Answer
More Answers (0)
Categories
Find more on Automated Fixed-Point Conversion in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!