Integers can only be raised to positive integral powers in db2mag computation
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Nitin Kapgate
2021년 1월 13일
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
Life is Wonderful
2021년 1월 13일
편집: Life is Wonderful
2021년 1월 13일
Life is Wonderful
2021년 1월 15일
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
2021년 1월 18일
카테고리
도움말 센터 및 File Exchange에서 Fixed-Point Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!