Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: manipulating strings
Date: Wed, 8 Jul 2009 07:49:01 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 39
Message-ID: <h31j1d$b16$1@fred.mathworks.com>
References: <87c67726-964b-48ce-80f0-a50d24b62cd1@26g2000yqk.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1247039341 11302 172.30.248.35 (8 Jul 2009 07:49:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 8 Jul 2009 07:49:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:553653

arun <aragorn168b@gmail.com> wrote in message <87c67726-964b-48ce-80f0-a50d24b62cd1@26g2000yqk.googlegroups.com>...
> Hi,
> 
> suppose I have a string A whose size is 1*10^7. I would now like to
> remove certain characters in the string. I tried strfind and regexprep
> as follows
> 
> A(strfind(A, ',')) = ''; %replace entries with a comma with nothing
> and then i repeat this for all numbers from 0 to 9 and for "space".
> 
> Alternative efficient way i hoped would be,
> A = regexprep(A, "[0-9, ]", '');
> but the first expression takes for ever as the vector is long and the
> second one strangely gives me "out of memory" error...
> 
> 
> any ways to speed up?
> 
> thank you very much,
> arun.

one of the solutions
- use ISMEMBC rather than ISMEMBER

     clear ix v;     % <- save old stuff
     tmpl='0':'z';
     v=repmat(tmpl(randperm(numel(tmpl))),1,600000);
     size(v,2)
%    ans = 45,000,000
     tmpl=sort(['0':'9',',']);     % <- must be SORTed!
tic;
     ix=ismembc(v,tmpl);
toc
%{
Elapsed time is 0.558719 seconds.
% wintel system: ic2/2*2.6gzh/2mb/winxp.sp3/r2009a
%}

us