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
M = min( A ) returns the minimum elements of an array. If A is a vector, then min(A) returns the minimum of A . If A is a matrix, then min(A) is a row vector containing the minimum value of each column of A .
min index(es) is the index for the first min value. If array is multidimensional, min index(es) is an array whose elements are the indexes for the first minimum value in array.
You can use max() to get the max value. The max function can also return the index of the maximum value in the vector. To get this, assign the result of the call to max to a two element vector instead of just a single variable.
k = find( X , n ) returns the first n indices corresponding to the nonzero elements in X . k = find( X , n , direction ) , where direction is 'last' , finds the last n indices corresponding to nonzero elements in X .
Try min
with the colon
operator, then ind2sub
:
[xmin,ind] = min(D(:));
[ii,jj,kk] = ind2sub(size(D),ind)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With