Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!e23g2000prf.googlegroups.com!not-for-mail
From: Palle Uldenborg <palle.uldenborg@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: The N largest values of an M x 1 matrix
Date: Thu, 3 Jan 2008 08:34:33 -0800 (PST)
Organization: http://groups.google.com
Lines: 25
Message-ID: <7222b5d8-b1b3-425c-be43-ac349257c5e7@e23g2000prf.googlegroups.com>
References: <57537254-3f7e-43e4-8fc4-75d8de63b3d6@s8g2000prg.googlegroups.com> 
NNTP-Posting-Host: 90.184.80.53
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1199378074 30817 127.0.0.1 (3 Jan 2008 16:34:34 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 3 Jan 2008 16:34:34 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: e23g2000prf.googlegroups.com; posting-host=90.184.80.53; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en; rv:1.8.1.11) 
Xref: news.mathworks.com comp.soft-sys.matlab:444214


On Jan 3, 3:39 pm, "Jos " <DEL...@jasenDEL.nl> wrote:
> Palle Uldenborg <palle.uldenb...@gmail.com> wrote in message
> <57537254-3f7e-43e4-8fc4-75d8de63b...@s8g2000prg.googlegroups.com>...
> > I would like to find the indexes of the N largest elements of an   M x
> > 1 matrix. right now I do something lik the following, but
> > it doesn't scale well.
> > N=10;M=100;a=rand(1,M);[val,ip]=sort(a);idx=ip(end-N:end);a(idx)
> > Does matlab have a specialized function for this?
> What do you mean by "it doesn't scale well"?

Thank you for your answer. Sorry if I was unclear.

I meant that for for a fixed value of N the CPU cost does not scale
linearly with M.

I am interested in situations such as N=5 and M=100000, so I think
that I could gain from a matlab function that did some kind of partial
sorting.

                       Niels