Using Typecast Function in Code Generation

7 Ansichten (letzte 30 Tage)
Aaron Pfalzgraf
Aaron Pfalzgraf am 28 Mär. 2016
Beantwortet: Walter Roberson am 28 Mär. 2016
Good afternoon,
I am trying to use the typecast function for a project with code generation.
% where temp2 is a double that is less than 0
temp = typecast((65535-(temp2*100)),'uint16');
liftangle = temp;
I get the following error:
Data 'liftangle' (#81) is inferred as a variable size matrix, while its specified type is something else.
I have also tried to replicate the above code without using typecast, but the Code Optimizer is rounding all negatives to 0 before I get a chance to do anything.
% Matlab Function Code
temp = double(((dutycycle-sensor_map(2))/sensor_map(1))-zero_value);
if temp < 0
temp = (65535-(temp*100));
angle = uint16(temp);
else
angle = uint16(temp*100);
end
tmp = (int32_T)rt_roundd(((((((real_T)rtb_LiftAngle_o1) * 1.52587890625E-5)
* 100.0) - 55.8) / 0.643) - zero_value);
if (tmp >= 0) {
rtb_DataTypeConversion40 = (uint16_T)tmp;
} else {
rtb_DataTypeConversion40 = 0U;
}

Antworten (1)

Walter Roberson
Walter Roberson am 28 Mär. 2016
if dutycycle - zerovalue * sensormap(1)
... then the result will be negative
With regards to
temp = typecast((65535-(temp2*100)),'uint16');
to understand this we need to know the data type of temp2. If it is not int16 or uint16 then (65535-(temp2*100) does not have the same storage size as uint16 and so the typecast would either fail (if temp2 is int8 or uint8) or would produce multiple outputs (if temp2 is int32, uint32, single, or double)

Kategorien

Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by