Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!uns-out.usenetserver.com!news.usenetserver.com!pc02.usenetserver.com!fe085.usenetserver.com.POSTED!53ab2750!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: simple regexp question
References: <g7scqd$lbp$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X)
Message-ID: <see-B4663B.13334712082008@softbank060082049208.bbtec.net>
Lines: 32
Date: Tue, 12 Aug 2008 13:33:47 -0400
NNTP-Posting-Host: 74.44.86.132
X-Complaints-To: abuse-news@frontiernet.net
X-Trace: fe085.usenetserver.com 1218562428 74.44.86.132 (Tue, 12 Aug 2008 13:33:48 EDT)
NNTP-Posting-Date: Tue, 12 Aug 2008 13:33:48 EDT
Organization: Frontier
Xref: news.mathworks.com comp.soft-sys.matlab:485102



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.