Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Construct a 2D matrix whose each element is the maximum among the receptive elements of multiple 2D matrices constructed by a 3D matrix.

1 回表示 (過去 30 日間)
Ahmad
Ahmad 2016 年 2 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
The best way to explain what I'm trying to do is with an example. Say I have the following 2*2*3 matrix.
A(:,:,1) =
10 20
20 30
A(:,:,2) =
100 5
10 50
A(:,:,3) =
170 10
100 12
I want to construct a new 2D matrix (call is Amax) whose every (ith,jth) element is the maximum among the 2D matrices' elements of the original 3D matrix. For the above example, the new matrix Amax should be
Amax =
170 20
100 50
Also, I need to know which 3rd dimension of the original 3D matrix the elements in Amax came from. So I need a second 2D matrix (call is INDEX) whose elements are the 3rd dimension of the original 3D matrix. For the above example, the new matrix INDEX should be
INDEX =
3 1
3 2
I don't what to use for loops, as the size of my 3D matrix is large. I need to vectorize the above operation.
thank you in advanced Ahmad

回答 (1 件)

Roger Stafford
Roger Stafford 2016 年 2 月 22 日
編集済み: Roger Stafford 2016 年 2 月 22 日
[B,I] = max(A,[],3);
B gives the 2D matrix of maximums along the third dimension and I gives the corresponding 3rd dimension indices. Read
http://www.mathworks.com/help/matlab/ref/max.html
  1 件のコメント
Ahmad Abuaish
Ahmad Abuaish 2016 年 2 月 22 日
Thank you very much Roger for the prompt response. It worked!

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by