From: Rahul Singhal on
Hi All,
I have a matrix which contains some negative values. I want to get the indices of top 'k' most negative values in matrix.

How can i do that?

Thanks and Regards
Rahul
From: dpb on
Rahul Singhal wrote:
> Hi All,
> I have a matrix which contains some negative values. I want to get the
> indices of top 'k' most negative values in matrix.
> How can i do that?
....

Would that not be the k smallest entries?

If so, the brain-dead way would be

xsort = sort(x(:));
min_k = xsort(1:k);

--
From: Roger Stafford on
"Rahul Singhal" <rsinghalomatic(a)gmail.com> wrote in message <i0vn5o$sqt$1(a)fred.mathworks.com>...
> Hi All,
> I have a matrix which contains some negative values. I want to get the indices of top 'k' most negative values in matrix.
>
> How can i do that?
>
> Thanks and Regards
> Rahul
- - - - - - - - -
Check out this FEX contribution by Bruno Luong:

http://www.mathworks.com/matlabcentral/fileexchange/23576-minmax-selection

Roger Stafford
From: Oleg Komarov on
"Rahul Singhal" <rsinghalomatic(a)gmail.com> wrote in message <i0vn5o$sqt$1(a)fred.mathworks.com>...
> Hi All,
> I have a matrix which contains some negative values. I want to get the indices of top 'k' most negative values in matrix.
>
> How can i do that?
>
> Thanks and Regards
> Rahul

k = 9;
A = rand(10,10);
[sortedA, idx] = sort(A(:));
kMostNeg = idx(end-k:end);

Oleg
From: Oleg Komarov on
typo, last line should be:
kMostNeg = idx(end-k+1:end);

Oleg