From: Bruno Luong on 28 Apr 2010 16:08 OK, as everyone come up to the same solution; here is a different method without using sub2ind M=rand(8,20,20) % Engine [M3 idx3] = min(M, [], 3); [M2 idx2] = min(M3, [], 2); [M1 idx1] = min(M2, [], 1); idx1 idx2=idx2(idx1) idx3=idx3(idx1,idx2) % Check M(idx1,idx2,idx3) min(M(:)) % Bruno
From: Bruno Luong on 28 Apr 2010 17:43 In recursively way just for fun: function varargout = ndmin(M) nd = ndims(M); if nd==2 && size(M,2)==1 [~, varargout{1}] = min(M, [], 1); else [M I] = min(M, [], nd); [varargout{1:nd-1}] = ndmin(M); varargout{nd} = I(varargout{1:nd-1}); end end % ndmin %% Command line M=rand(8,20,20); [n m t]=ndmin(M) % Bruno
From: Matt J on 29 Apr 2010 02:19 "Erik Andersson" <annerk02(a)student.umu.se> wrote in message <hra24c$di4$1(a)fred.mathworks.com>... > Hello! > I have a n*m*t matrix wher a=8, b=20, c=20. In this matrix a have calculated error in different values. Now I want to find the indexvalues, i.e. the values of n, m and t where the minimumerrorvalue of the matrix is? ======= Are you sure it's not enough just to find the linear lindex of the minimizer? [trash, LinearIndex]=min(TheMatrix(:)); If so, it could save you computation.
First
|
Prev
|
Pages: 1 2 Prev: bluring an image with 1D FIR filter Next: Execute an m file from the command line |