Integers can only be raised to positive integral powers in db2mag computation
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Nitin Kapgate
il 13 Gen 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 Commenti
Life is Wonderful
il 13 Gen 2021
Modificato: Life is Wonderful
il 13 Gen 2021
Life is Wonderful
il 15 Gen 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
il 18 Gen 2021
Categorie
Scopri di più su Fixed-Point Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!