Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: simple regexp question
Date: Tue, 12 Aug 2008 17:45:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 41
Message-ID: <g7si70$ko6$1@fred.mathworks.com>
References: <g7scqd$lbp$1@fred.mathworks.com> <see-B4663B.13334712082008@softbank060082049208.bbtec.net>
Reply-To: <HIDDEN>
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 1218563104 21254 172.30.248.38 (12 Aug 2008 17:45:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 12 Aug 2008 17:45:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 939004
Xref: news.mathworks.com comp.soft-sys.matlab:485108



Doug Schwarz <see@sig.for.address.edu> wrote in message
<see-B4663B.13334712082008@softbank060082049208.bbtec.net>...
> In article <g7scqd$lbp$1@fred.mathworks.com>,
>  "matt dash" <n.a@mail.com> wrote:
> 
> > Hello,
> > 
> > I have a cell array of strings, each of which looks like :
> > 
> > 'Lambda46' => '54.954684760469313', 
> > 
> > (including the quotes and comma) and I want to extract the
> > two numbers 46 and 54.954... and put them in vectors.
> > Normally I would do this by finding the locations of the
> > quotes and working from there, but I suspect there's a
> > better way using regular expressions and I figure it's about
> > time I started using them... is there a simple way to do
this?
> 
> I know you asked for a solution using regular expressions,
but really 
> this sort of problem is ideal for textscan.  Suppose your
cell array of 
> strings is C, then
> 
>   str = sprintf('%s\n',C{:});
>   a = textscan(str,'''Lambda%n'' => ''%n'',');
>   col1 = a{1};
>   col2 = a{2};
> 
> will give you all the first numbers in a vector, col1, and
all the 
> second numbers in a vector, col2.
> 
> -- 
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

Thanks, thats just what I was looking for.