How can I get the indices of \"n smallest elements\" in a 1D array in MATLAB?
The array is a row vector.
I can find the smallest element and its index using
I know this is an extremely late reply but I am hoping to help anyone who may have this question later.
If A is the array of elements, yu could try using the find function to determine the index of the n smallest elements.
[~, idx] = find(A > -Inf, n, 'first')
To determine the n largest elements,
[~, idx] = find(A < Inf, n, 'last')