Path: news.mathworks.com!not-for-mail
From: "Steven_Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Recoding a vector to string (a big one)
Date: Mon, 23 May 2011 11:08:04 -0400
Organization: MathWorks
Lines: 35
Message-ID: <irdt8k$mkk$1@newscl01ah.mathworks.com>
References: <d080f2d7-2789-409e-9dde-b0a471ab89fd@l6g2000vbn.googlegroups.com>
NNTP-Posting-Host: ah-slord.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="iso-8859-1";
	reply-type=original
Content-Transfer-Encoding: 7bit
X-Trace: newscl01ah.mathworks.com 1306163284 23188 172.31.44.225 (23 May 2011 15:08:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 23 May 2011 15:08:04 +0000 (UTC)
In-Reply-To: <d080f2d7-2789-409e-9dde-b0a471ab89fd@l6g2000vbn.googlegroups.com>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: news.mathworks.com comp.soft-sys.matlab:728286



"Kirill" <kirillandreev@gmail.com> wrote in message 
news:d080f2d7-2789-409e-9dde-b0a471ab89fd@l6g2000vbn.googlegroups.com...
> Dear all,
> I need to recode vector v into string array given give a recoding
> table lev and str.   I used to do something like that:
> v = [1 1 2 2 3];
>
> lev = [1 2 3];
> str = {'a' 'b' 's'};
>
> [~, idx] = ismember(v, lev);
> v_recoded = str(idx)
>
> Once number of levels hits hundreds of thousands this becomes too slow
> to live with it.  I would really prefer to keep lev sorted in advance
> so I could reduce time for searching elements within this array.  I
> looked at the map object and the dataset objects in the statistical
> toolbox but I cannot find desired functionality.
> Do I need to write custom code or I am missing something here?

Are all the levels positive integer values? If so, just use indexing 
directly.

str = {'a', 'b', 's'};
v = [1 1 2 2 3];
c = str(v)

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com