minimum of a 3D matrix
Show older comments
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!
Accepted Answer
More Answers (1)
Image Analyst
on 31 Oct 2012
Try this:
minOfPlane = min(min(M(:,:, t)))
9 Comments
Qian
on 31 Oct 2012
Walter Roberson
on 31 Oct 2012
If you want to do all the planes simultaneously, min(min(M)) . You might want to squeeze() the result to make it a column vector.
Qian
on 31 Oct 2012
Walter Roberson
on 31 Oct 2012
[minM idx] = min(reshape(M(:,:,1),[],1)); %first plane only
or, for all simultaneously,
[minM idx] = min(reshape(M, [], size(M,3)));
Qian
on 31 Oct 2012
Walter Roberson
on 31 Oct 2012
[minM idx] = min(reshape(M, [], size(M,3)));
idx = idx + (size(M,1)*size(M,2)).*(0:2);
[n m t] = ind2sub(size(M), idx);
Qian
on 31 Oct 2012
Andrei Bobrov
on 31 Oct 2012
[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
on 31 Oct 2012
Ah yes, the 0:2 I used should be 0:size(M,3)-1
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!