MATLAB: Minimum of a 3D matrix

matrix

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!

Best Answer

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)' ]