# In fi(var1,var2,...varN) if var1 is not a constant then

12 views (last 30 days)
Tamer on 29 Mar 2016
Edited: Stephen23 on 18 Jan 2022
Hello There,
I want your help please to convert a double array to fixed point and keep the FractionLength of each variable in array separate
I'm trying to convert a variable array (wi) from double to fixed point. The variables of the array have a different FractionLength fraction as showing below, and when I do "wi=fi (wi,1)"; it takes a round FractionLength for the entire array which affect the values of each variable.
>> fi(wi(1,1))
ans =
0.3956
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 16
>> fi(wi(1,3))
ans =
-0.1145
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 18
but if I do a fixed point for the entire array (fi(wi))
>> fi(wi)
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 13
I tried to do the conversation of fixed point without indicating the FractionLength as below, but I got this error message.
wi=fi (wi,1,16)
Error "In fi(var1,var2,...varN) if var1 is not a constant then var2 to varN must be or specify a complete numerictype."
Can you please help me to do this on the right way?
Thank you in advance

Jeevan Joishi on 4 Apr 2016
Edited: Stephen23 on 18 Jan 2022
The fixed-point properties WordLength and FractionLength are part of a fixed-point number's datatype. Fixed-point numbers with different FractionLength/WordLength are considered different data types.
In MATLAB, an array can be used to store multiple elements of the same datatype. Therefore an array cannot be used to store fixed-point numbers of different WordLength/FractionLength because their data types are different.
Alternatively, a cell array can be used to store fixed-point number with different WordLength/FractionLength.
For instance,
>> wi = {16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1};
>> fiOut = cellfun(@fi,wi,'UniformOutput',false);
It is not possible to apply 'fi' directly on the entire cell array. Thus you can use 'cellfun' to apply the function to each element of the cell array 'wi'.
##### 2 CommentsShowHide 1 older comment
Stephen23 on 18 Jan 2022
Edited: Stephen23 on 18 Jan 2022
@Jogger: the code given in the answer was clearly incorrect and does not work. I have corrected it.
As the error message states, rather than using a character vector 'false' you should use a logical value:
wi = {16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1};
fiOut = cellfun(@fi,wi,'UniformOutput',false)
fiOut = 4×4 cell array
{1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi} {1×1 embedded.fi}