File Exchange

image thumbnail

Min and Max for Array

version (2.09 KB) by Durga Lal Shrestha
Find kth smallest or largest values and their indices.

1 Download

Updated 27 Jul 2012

View License

MINMAX find kth smallest or largest values and their indices.

vals = minmax(data) % find minimum
vals = minmax(data,k) % find kth smallest values
vals = minmax(data,k,flag) % find kth largest values
[vals,loci] = minmax(:)
[vals,loci,locj] = minmax(:) for 2 d array
[vals,loci,locj,...] = minmax(:) % for multi dimensional array

data - two dimensional data
k - number of smallest or largest values required
flag - whether min or max

vals - smallest or largest values
loci - index to the row
locj - index to the column

data = 1:16;
data = reshape(data,4,4);
[out,loci,locj] = minmax(data,5) % find the 5 smallest vaues and
their locations
[out,loci,locj] = minmax(data,5,'max) % find the 5 largest vaues and
their locations

Cite As

Durga Lal Shrestha (2021). Min and Max for Array (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

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

Inspired: Transformation matrix for stress and strain

Community Treasure Hunt

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

Start Hunting!