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 01:24:03 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 34
Message-ID: <fogavj$ae4$1@fred.mathworks.com>
References: <5b74607b-c527-4c9b-833a-b08d4be5d48a@s13g2000prd.googlegroups.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.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 1202433843 10692 172.30.248.38 (8 Feb 2008 01:24:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 8 Feb 2008 01:24:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:450029


Pietro <pietromas@gmail.com> wrote in message <5b74607b-c527-4c9b-
833a-b08d4be5d48a@s13g2000prd.googlegroups.com>...
> Its hard to explain but an example of what I need is:
> 
> [3 7 2 2 3 100 7 56] => [1 2 3 3 1 4 2 5]
> 
> I have a large vector containing many numbers including duplicates.
> 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.
> 
> The vector is very large, say 2e4 to 2e6 elements. I cant figure out
> how to vectorize it. The best I have been able to do is:
> 
>         % input is vec
>         uniques = unique(vec); % the mapping
>         mapped_vec = zeros(length(uniques), 1); % pre-allocate
>         for i = 1:length(uniques);
>                 mapped_vec(vec == uniques(i)) = i; % replace each
> element with its new value from the map
>         end;
> 
> The loop body is accounting for 95% of my execution time. Need to get
> some speed. HELP!

help unique

I wonder if its possible that the other returned
arguments might be of interest. The third one
maybe?

John