how do I average each 10 elements of a matrix?
    10 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    nadia naji
 el 21 de Abr. de 2021
  
    
    
    
    
    Comentada: Walter Roberson
      
      
 el 21 de Abr. de 2021
            Hi, 
I have an 80x1 vector and I need to average every 10 elements from first and save them to a new vector. do you have any suggestions except for the loop? (average of first 10 elements, an average of second 10 elements, ...). thank you.
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 21 de Abr. de 2021
        mean10 = mean(reshape(Vector, 10, []),1)
3 comentarios
  Walter Roberson
      
      
 el 21 de Abr. de 2021
				frame_length = 10;
Veclen = length(Vector);
num_frame = floor(Veclen/frame_length);
num_extra = Veclen - num_frame * frame_length;
frame_means = [mean(reshape(Vector(1:end-num_extra), frame_length, []),1), mean(Vector(end-num_extra+1:end)]
This code is designed so that if there are left over samples at the end, then it takes the mean of what exists.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Logical 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!

