Path: news.mathworks.com!not-for-mail
From: "Adam " <crossroads_evh.nospam@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Array manipulation question
Date: Tue, 21 Aug 2007 18:22:32 +0000 (UTC)
Organization: Adam Parry (ID: 1-16WL0L)
Lines: 18
Message-ID: <fafah8$ot$1@fred.mathworks.com>
Reply-To: "Adam " <crossroads_evh.nospam@hotmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187720552 797 172.30.248.38 (21 Aug 2007 18:22:32 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 21 Aug 2007 18:22:32 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 292301
Xref: news.mathworks.com comp.soft-sys.matlab:424820



Hi everyone,
   I'm looking for a way to have Matlab return some number 
(N) of the smallest elements in an array along with their 
indices in the array.  For example, given the array:

[5 4 3 2 1] and N = 3

The output should be something like:

[[3 3],[2 4],[1 5]]

This can be done with brute force but I'm looking for a 
cleaner implementation.  I can't use the sort function 
because it re-orders the array and I would lose the index 
information.  Does matlab support hash tables?  Any other 
ideas?  Thanks.

Adam