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$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1245031561 5993 (15 Jun 2009 02:06:01 GMT)
NNTP-Posting-Date: Mon, 15 Jun 2009 02:06:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1652144
Xref: 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!