Finding the index of the smallest element in a 3-dimensional matrix (or n-dimensional)
matlab, matrix, octave
Solution
Try `min` with the `colon` operator, then `ind2sub`:
[xmin,ind] = min(D(:));
[ii,jj,kk] = ind2sub(size(D),ind)
Problem
I have a matrix `D(i,j,k)` and I want to find `i`,`j`,`k` so as to minimize `x`: ``` x = D(i,j,k) ``` For example: ``` D = rand(10,10,10); min(min(min(D))) = 0.5123; %The smallest element in D ``` What I want to know is the index of D that gives 0.5123 How can I do this? Thanks, Elliot