image thumbnail

N largest values and locations in multidimensional array

version (1.66 KB) by Alan Jennings
Returns the N largest values for a multidimensional array, and their subscripts.


Updated 26 Nov 2010

View License

For arbitrary sized arrays, it sorts the effective column array and returns the largest n elements. The column index of maximum are converted into subscripts which are returned as rows in array. Option exists to only consider unique values.

Not optimized, but meant to be functional for most cases. Not tested on sparse arrays. Function is just recommended as a handy function to put in your personal toolbox.

To find minimum values, just negate the input dataset and the output values.

Cite As

Alan Jennings (2022). N largest values and locations in multidimensional array (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!