Find Maximum Values of a 3 Dimensional Matrix
조회 수: 78 (최근 30일)
이전 댓글 표시
I need to find each maximum values (position/indexing of values) of each layer on a 3 dimensional matrix.
It was given for a two dimensional matrix.
example:
--------------------
A = [8 2 4; 7 3 9];
[M,I] = max(A(:));
[I_row, I_col] = ind2sub(size(A),I)
---------------------
Here I_row and I_col is could be found. But I need a 3 dimensional matrix's maximum indexing of each layers.
Example:
---------------------
F(:,:,1)=[8 2 4; 7 3 9];
F(:,:,2)=[7 2 1; 0 5 1];
---------------------
I need position of 9 for the 1'st layer (which is (2,3)), and also position of the 7 for the 2'nd layer (which is (2,1)).
That layers are going up to 150 or more. (F(:,:,150))
So, how can I find each of the maxsimum of the matrix?
Thanks in advance.
댓글 수: 0
채택된 답변
Thorsten
2015년 11월 18일
Reshape the pages of F into separate columns, determine the max for each column and use ind2sub to convert linear indices to subscripts:
[s1 s2 s3] = size(F);
[maxval, ind] = max(reshape(F(:), s1*s2, []));
[i j] = ind2sub([s1 s2], ind);
X = [maxval' i' j'];
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle Swarm에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!