Converting a 3D matrix in 2D matrix by making a average
13 ビュー (過去 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
2020 年 5 月 26 日
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
2020 年 5 月 26 日
You can specify the dimension in mean. Read about it.
iwant = mean(A,3)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!