Converting a 3D matrix in 2D matrix by making a average
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I have a 3D 7x15x38 matrix, I would like to convert it to 2D 7x15 and average the values of the 3rd dimension.
Taking a simpler system, I would like to do this operation:
3D (2,2,3) matrix :
1 2 5 6 7 8
3 4 7 8 9 10
in 2D (2,2) matrix :
(1 + 5 + 7)/3 (2 + 6 + 8)/3 4,3 5,3
(3 + 7 + 9)/3 (4+8+10)/3 = 6,3 7,3
Do you have any tips ?
Thanks in advance
2 comentarios
Constantino Carlos Reyes-Aldasoro
el 26 de Mayo de 2020
Hello
This is easy, you can use the function mean directly, you only need to indicate the dimension you want the mean to be calculated
a = mean(b,3);
Normally when you use mean with only one argument, it will calculate the mean over the columns, or if you want the mean of all elements you can do it like this
a = mean (b(:));
Notice that you can also do the same with maximum or minimum but the syntax is slightly different:
a = max(b,[ ],3);
Hope this helps. If you need anything else, let me know.
Respuestas (1)
KSSV
el 26 de Mayo de 2020
You can specify the dimension in mean. Read about it.
iwant = mean(A,3)
0 comentarios
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!