4.0

4.0 | 2 ratings Rate this file 5 Downloads (last 30 days) File Size: 6.22 KB File ID: #8568

A C-mex Function to find N largest number in a Matrix

by Changshun Deng

 

27 Sep 2005 (Updated 28 Sep 2005)

A c-mex function to find N largest number in a matrix.

| Watch this File

File Information
Description

This is a C-Mex Fucntion to find n largest number in a matrix.

>> x=randperm(20);
>> nmax(x,5)

ans =

    20 19 18 17 16

>> nthmax(x,5)

ans =

    16

MATLAB release MATLAB 6.5.1 (R13SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
28 Sep 2005 Jos x

Same as
b = sort(a) ; b(end-N)
or
b = unique(a) ; b(end-N)
depending on the exact definition of Nth largest number. Both sort and unique are faster than your routines ...

04 Oct 2005 Changshun Deng

i don't know if run my program.
just compare these results:

>> tic;nmax(x,1);toc

elapsed_time =

    0.2030

>> tic;max(x);toc

elapsed_time =

    1.3910

>> x=rand(1000,10000);
>> tic;nmax(x,10);toc

elapsed_time =

   10.1880

>> tic;y = sort(x) ; y(end-10);toc

elapsed_time =

   29.4380

04 Oct 2005 Changshun Deng

>> x=rand(1000,10000);

>> tic;y = sort(x) ; y(end-10);toc

elapsed_time =

   17.8590

>> tic;nmax(x,10);toc

elapsed_time =

    3.7350

22 May 2006 Rudran Rudran  
04 Jun 2006 bainhome webID

support my friend£¡

29 Jun 2006 Giovani Tonel  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
max Changshun Deng 22 Oct 2008 08:00:50
cmex Changshun Deng 22 Oct 2008 08:00:50
c mex Changshun Deng 22 Oct 2008 08:00:50
largest Changshun Deng 22 Oct 2008 08:00:50
number Changshun Deng 22 Oct 2008 08:00:50
matrix Changshun Deng 22 Oct 2008 08:00:50

Contact us at files@mathworks.com