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

조회 수: 13 (최근 30일)
Manon Sonnet
Manon Sonnet 2020년 5월 26일
댓글: Manon Sonnet 2020년 5월 26일
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
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 2020년 5월 26일
Thanks a lot !

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2020년 5월 26일
You can specify the dimension in mean. Read about it.
iwant = mean(A,3)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by