필터 지우기
필터 지우기

minimum of a 3D matrix

조회 수: 12 (최근 30일)
Qian
Qian 2012년 10월 31일
M=rand(2,2,3)
[minM idx] = min(M(:));
[n m t] = ind2sub(size(M),idx)
minM
M(n,m,t)
I know this will give the minimum of the M matrix.
However, I want minimum value only for each M(:,:,i) part.
Is there anyway to do that?
Thanks in advance!

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 31일
편집: Azzi Abdelmalek 2012년 10월 31일
M=rand(2,2,3);
out=min(reshape(min(M),size(M,2),[],1))'
or
out=arrayfun(@(x) min(min(M(:,:,x))),1:size(M,3))'
If you want to get the corresponding index
M=rand(6,4,5);
[n,m,p]=size(M)
[c,idx]=min(M)
[c1,idx2]=min(c)
idx1=arrayfun(@(x) idx(1,idx2(1,1,x),x),(1:p)')
v=[c1(:) idx1(:) idx2(:) (1:p)' ]

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 10월 31일
Try this:
minOfPlane = min(min(M(:,:, t)))
  댓글 수: 9
Andrei Bobrov
Andrei Bobrov 2012년 10월 31일
[v, i1] = min(reshape(M,[],size(M,3)));
min_idx_m_n_t = [rem(i1-1,size(M,1))+1; ceil(i1/size(M,1)); 1:size(M,3)]';
Walter Roberson
Walter Roberson 2012년 10월 31일
Ah yes, the 0:2 I used should be 0:size(M,3)-1

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

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by