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

조회 수: 1 (최근 30일)
Tamer
Tamer 2016년 3월 29일
편집: Stephen23 2022년 1월 18일
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

답변 (1개)

Jeevan Joishi
Jeevan Joishi 2016년 4월 4일
편집: Stephen23 2022년 1월 18일
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
Life is Wonderful
Life is Wonderful 2022년 1월 18일
wi = {16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1};
fiOut = cellfun(@fi,wi,'UniformOutput','false');
Error using cellfun
Input #4 expected to be a logical value for the parameter 'UniformOutput'.
fiOut
Stephen23
Stephen23 2022년 1월 18일
편집: Stephen23 2022년 1월 18일
@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}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 HDL Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by