How to compute harmonic average on the blocks of an array?
    9 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Nisar Ahmed
 el 17 de Ag. de 2022
  
    
    
    
    
    Comentada: Nisar Ahmed
 el 18 de Ag. de 2022
            Hi,
I have attached the data Mmin, I want to compute the harmonic average of first 4 values and then next 4 and so on. In short in the blocky form and each block is of 4 values.
Just like shown in the attached figure. after taking harmonic mean of first four values, there will be one value  instead of four and so on.
Can someone help me to write it code?
Thanks

0 comentarios
Respuesta aceptada
  David Hill
      
      
 el 17 de Ag. de 2022
        a=randi(100,1,100);%some vector
for k=1:length(a)-3
  A(k)=harmmean(a(k:k+3));
end
4 comentarios
  David Hill
      
      
 el 18 de Ag. de 2022
				
      Editada: David Hill
      
      
 el 18 de Ag. de 2022
  
			I misunderstood you. I thought you wanted a rolling harmonic mean 1-4 then 2-5, then 3-6, 4-7, etc. I simple change will correct.
a=randi(100,1,32);%some vector
c=1;
for k=1:4:length(a)-3
  A(c)=harmmean(a(k:k+3));
  c=c+1;
end
A
Or 
m=movsum(1./a,4,'Endpoints','discard');
A=4./m(1:4:end)
Más respuestas (0)
Ver también
Categorías
				Más información sobre Multidimensional Arrays 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!

