Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!news.glorb.com!postnews.google.com!v31g2000vbs.googlegroups.com!not-for-mail
From: Kirill <kirillandreev@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Recoding a vector to string (a big one)
Date: Tue, 31 May 2011 14:52:24 -0700 (PDT)
Organization: http://groups.google.com
Lines: 49
Message-ID: <b0478a76-c879-4594-a92f-c202ad701aca@v31g2000vbs.googlegroups.com>
References: <d080f2d7-2789-409e-9dde-b0a471ab89fd@l6g2000vbn.googlegroups.com> <irdt8k$mkk$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: 157.150.192.237
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1306878744 30203 127.0.0.1 (31 May 2011 21:52:24 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 31 May 2011 21:52:24 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: v31g2000vbs.googlegroups.com; posting-host=157.150.192.237; posting-account=fkb0ygoAAABvmsDkMbuz3TaDG_7cNs9o
User-Agent: G2/1.0
X-HTTP-Via: 1.1 unhq-squid-02.un.org:3128 (squid/2.6.STABLE22)
X-Google-Web-Client: true
X-Google-Header-Order: ARLUEHCVFNK
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;
 Trident/4.0; MathPlayer 2.10d; GTB6.4; .NET CLR 2.0.50727; InfoPath.1; .NET
 CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.3),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:729570

On May 23, 11:08 am, "Steven_Lord" <sl...@mathworks.com> wrote:
> "Kirill" <kirillandr...@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
> sl...@mathworks.com
> To contact Technical Support use the Contact Us link onhttp://www.mathworks.com- Hide quoted text -
>
> - Show quoted text -

Thank you, Steve.  The idea is to attach a database-like index to lev
variable to make lookup faster so ismember() function could take
advantage of it.  This would be useful for very large lev vectors/
matrices/datasets.  Maybe it’s been implemented already in Statistics
Toolbox – I need to check it out.

Kirill