In fi(var1,var2,...varN) if var1 is not a constant then
    11 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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
0 comentarios
Respuestas (1)
  Jeevan Joishi
    
 el 4 de Abr. de 2016
        
      Editada: Stephen23
      
      
 el 18 de En. de 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 comentarios
  Life is Wonderful
 el 18 de En. de 2022
				wi = {16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1};
fiOut = cellfun(@fi,wi,'UniformOutput','false');
fiOut
  Stephen23
      
      
 el 18 de En. de 2022
				
      Editada: Stephen23
      
      
 el 18 de En. de 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)
Ver también
Categorías
				Más información sobre HDL Coder en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


