Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: How to parse a string? (Simple question)
Date: Mon, 15 Jun 2009 02:06:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <h14aa9$5r9$1@fred.mathworks.com>
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 1245031561 5993 172.30.248.38 (15 Jun 2009 02:06:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 15 Jun 2009 02:06:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1652144
Xref: news.mathworks.com comp.soft-sys.matlab:547400

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!