File Exchange

image thumbnail

findNsmallest

version 1.1 (3.22 KB) by

Finds the N smallest values in the input. Very fast.

0 Downloads

Updated

View License

Example:
x = findNsmallest( [4 4 10 5 3 8], 3)

x =
4 4 3

Written in c, so the operation is fast. Type "mex findNSmallest.c" in matlab before use.

You might need a free compiler if it was not installed with your matlab:
http://www.mathworks.com/support/compilers/R2012b/win64.html

Comments and Ratings (3)

lu li

lu li (view profile)

It would be perfect if returned values are in sorted order.

As is discussed for findNlargest, this function is intended for cases when you are choosing a small number of values from a large pool. If you choose 5 values from a pool of a million, this function is about 40 times faster than if you sort.

Renwen Lin

Updates

1.1

Added example to description

MATLAB Release
MATLAB 8.0 (R2012b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

findNsmallest/