Integers can only be raised to positive integral powers in db2mag computation
Show older comments
I am converting matlab code to c using fixed point coder app
I am getting the below error
Input to function db2mag_conv
decibelTomag.u1 = 10
decibelTomag.u2 = [-90:0.1:90]
function [y] = db2mag_conv(decibelTomag)
y = power(decibelTomag.u1,double(decibelTomag.u2/20))
end
Error signature
### Begin Fixed Point Simulation using Scaled Doubles : db2mag_conv
Error using >intpower', 'C:/Program Files/MATLAB/R2020b/toolbox/eml/lib/matlab/ops/power.m', 187)">power>>intpower (line 187)
Integers can only be raised to positive integral powers
I need help in resolving the error
Accepted Answer
More Answers (1)
Nitin Kapgate
on 13 Jan 2021
You will need to cast both "decibelTomag.u1" and "decibelTomag.u2" as single type (Fixed Point Coder App doesn't support doubles) as follows:
y = power(single(decibelTomag.u1),single(decibelTomag.u2/20))
This should help in getting your problem resolved.
4 Comments
Life is Wonderful
on 13 Jan 2021
Edited: Life is Wonderful
on 13 Jan 2021
Life is Wonderful
on 15 Jan 2021
Raising an integer value to a non-integer power does not necessarily result in an integer value.
y = 2^(1/2)
Nor does raising that integer to a non-positive integer power always result in an integer value.
w = 2^(-1)
Here's what I receive when I replace the double precision integer value 2 with a 2 stored in an integer type.
try, x = uint32(2)^(1/2), catch ME, disp("Error was:" + newline + ME.message), end
try, z = uint32(2)^(-1), catch ME, disp("Error was:" + newline + ME.message), end
You could try:
%{
function [y] = db2mag_conv(decibelTomag)
y = power(double(decibelTomag.u1),double(decibelTomag.u2/20))
end
%}
but I'm not sure if the two casts to double will cause problems in code generation.
Life is Wonderful
on 18 Jan 2021
Categories
Find more on Fixed-Point Conversion 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!