Converting a 3D matrix in 2D matrix by making a average

16 vues (au cours des 30 derniers jours)
Manon Sonnet
Manon Sonnet le 26 Mai 2020
Commenté : Manon Sonnet le 26 Mai 2020
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 commentaires
Constantino Carlos Reyes-Aldasoro
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.
Manon Sonnet
Manon Sonnet le 26 Mai 2020
Thanks a lot !

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 26 Mai 2020
You can specify the dimension in mean. Read about it.
iwant = mean(A,3)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by