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

12 次查看(过去 30 天)
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.

请先登录,再进行评论。

回答(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