Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to parse a string? (Simple question)
Date: Mon, 15 Jun 2009 02:39:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 31
Message-ID: <h14c86$3if$1@fred.mathworks.com>
References: <h14aa9$5r9$1@fred.mathworks.com>
Reply-To: "Sadik " <sadik.hava@gmail.com>
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 1245033542 3663 172.30.248.38 (15 Jun 2009 02:39:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 15 Jun 2009 02:39:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:547406


I guess you could do this:

markers = strread(data,'%f','delimiter','*#;');
markers(markers==0)=[];

Hope this helps.


"Kian " <kian.torab@utah.edu> wrote in message <h14aa9$5r9$1@fred.mathworks.com>...
> Last question for a few days, promise.
> 
> How do I pull out the numbers out of this string WITHOUT a loop?
> 
> data = '*12#;*123#;*1122#;*2#;*6312#;*112#;*1251#;*1912#;*8612#;
> 
> I basically want to be able to pull out the numbers, such as I'll have:
> 
> markers = [12, 123, 1122, 2, 6312, 112, 1251, 1912, 8612];
> 
> I can do this ONLY IF all the numbers are the same length (e.g. 3 digit numbers) using the indices of the '*'s and '#'s and bsxfun, but I don't know how to do it when the lengths are different. This is what I'd do if the lengths were the same.
> 
> starIndices = find(data == '*');
> poundIndices = find(data == '#');
> 
> data(bsxfun(@plus, starIndices, 1:(poundIndices-starIndices)-1);
> 
> But this only will give me the first 2 digits (since the first number in the string is only 2 digits long and that bsxfun will only use that to do its thing).
> 
> Any easier way to do this?
> 
> Thanks a lot for your time!