Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Optimize this!
Date: Fri, 8 Feb 2008 03:48:03 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 41
Message-ID: <fogjdj$r9o$1@fred.mathworks.com>
References: <5b74607b-c527-4c9b-833a-b08d4be5d48a@s13g2000prd.googlegroups.com> <fogavj$ae4$1@fred.mathworks.com> <fogepf$a4$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1202442483 27960 172.30.248.37 (8 Feb 2008 03:48:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 8 Feb 2008 03:48:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:450041


"us " <us@neurol.unizh.ch> wrote in message 
<fogepf$a4$1@fred.mathworks.com>...
> "John D'Errico":
> <SNIP has a bad hair day...
> 
> > I wonder if its possible that the other returned
> > arguments might be of interest. The third one
> > maybe...
> 
> hmmmmmm... <john>...
> 
> % the user wants
>      vu=[3 7 2 2 3 100 7 56];
>      ru=[1 2 3 3 1 4 2 5];
> 
> % now, we both know that none of <unique>'s outputs
> % will achieve this... in particular: #3 is useless

No. The author stated that the specific order
was not really necessary. Only the behavior.

To refresh your memory...

>> There is no order (well ... actually ordering them might be possible
>> if that helps but its not the default). Not all the numbers between
>> the minimum and the maximum are necessarily present. I need to
>> map the numbers in the vector to 1, 2, 3 etc.

a=[3 7 2 2 3 100 7 56];
[b,I,J] = unique(a);

J =
     2     3     1     1     2     5     3     4

Note that the ordering is different, but the
result is exactly as requested. The elements
are mapped to a list of indexes starting with 1
as requested. And, it takes only one function
call.

John