Mean of matrix subarrays without using a loop.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Santos García Rosado
el 16 de Mzo. de 2021
Comentada: Santos García Rosado
el 16 de Mzo. de 2021
Hi Mathworks community.
I'm trying to calculate the mean value of my matrix subarrays without taking the zero values into account. I know how to do it using a loop, but in this case I'd like to avoid it.
The code should take matrix A:
A = [1 0 3 5 0 7; 0 2 6 0 8 0; 3 5 0 0 2 0]
And calculate the mean value of the subarray for each row in steps of 3. So the output should look like:
Out = [2 6; 4 8; 4 2]
I'm trying to improve this code, since I'll be working with much bigger matrixes and I won't be able to do it manually:
Out = mean(nonzeros(A(1,1:3)));
Any help would be much appreciated.
Thanks in advance,
Santos
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and 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!