Thread Subject: String Operations

Subject: String Operations

From: Chris Wright

Date: 7 Nov, 2009 16:11:01

Message: 1 of 6

I was wondering if someone could give me some advice on some string manipulations (as i am newish to Matlab).

I have lots of strings in the form of (that are being extracted from an xml file):

-94%22%-4%92%-9%16%18%21%-31%-1%7%-20%9%14%19%22%-7%-1%3%13%-10%-1%0%11%-2%2%2%0%-3%5%1%-4%-3%-3%-3%-1%0%-3%-6%-15%-15%-6%-6%2%1%2%1%-9%1%0%2%2%2%3%3%0%0%0%0%-2%1%0%-3%-3%

with varying amount of numbers and numbers of upto 150 (for anyone who is interested these are the MPEG-7 image descriptors for SCD)..

What i want to do is extract the numbers (and signs) and put each one into a different cell in an array... so the % divides the numbers

any ideas for the best way ??

Subject: String Operations

From: dpb

Date: 7 Nov, 2009 16:34:01

Message: 2 of 6

Chris Wright wrote:
...
> I have lots of strings in the form of (that are being extracted from
> an xml file):
>
> -94%22%-4%92%-9%...
...

> any ideas for the best way ??

strread(s,'%d','delimiter','%')

would at least be one way (no claim for "best" :) )...

--

Subject: String Operations

From: Wrighty43 Wright

Date: 7 Nov, 2009 16:45:04

Message: 3 of 6

dpb <none@non.net> wrote in message <hd47i0$jbq$1@news.eternal-september.org>...
> Chris Wright wrote:
> ...
> > I have lots of strings in the form of (that are being extracted from
> > an xml file):
> >
> > -94%22%-4%92%-9%...
> ...
>
> > any ideas for the best way ??
>
> strread(s,'%d','delimiter','%')
>
> would at least be one way (no claim for "best" :) )...
>
> --
>

thanks that really helps, saves me messing around with sscanf

Subject: String Operations

From: dpb

Date: 7 Nov, 2009 16:57:28

Message: 4 of 6

Wrighty43 Wright wrote:
> dpb <none@non.net> wrote in message <hd47i0$jbq$1@news.eternal-september.org>...
>> Chris Wright wrote:
>> ...
>>> I have lots of strings in the form of (that are being extracted from
>>> an xml file):
>>>
>>> -94%22%-4%92%-9%...
>> ...
>>
>>> any ideas for the best way ??
>> strread(s,'%d','delimiter','%')
>>
>> would at least be one way (no claim for "best" :) )...
>>
...
> thanks that really helps, saves me messing around with sscanf

Yeah, it's handy for cases like this, for certain.

There's bound to be a way to get the stupid C format string to allow you
to enter a literal percent character as a character-matching character,
but I don't know just how that would be and it ain't worth futzin' w/
trying to figure out how since do have strread()

W/O strread(), I'd probably do a substitution of ' ' for '%' _then_ use
sscanf() just for the record.

--

Subject: String Operations

From: Steven Lord

Date: 8 Nov, 2009 23:36:19

Message: 5 of 6


"dpb" <none@non.net> wrote in message
news:hd48tv$v8q$1@news.eternal-september.org...
> Wrighty43 Wright wrote:

*snip*

> There's bound to be a way to get the stupid C format string to allow you
> to enter a literal percent character as a character-matching character,
> but I don't know just how that would be and it ain't worth futzin' w/
> trying to figure out how since do have strread()

I would try two percent characters.

>> fprintf('%%\n')
%

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: String Operations

From: dpb

Date: 8 Nov, 2009 23:52:31

Message: 6 of 6

Steven Lord wrote:
> "dpb" <none@non.net> wrote in message
...
>> There's bound to be a way to get the stupid C format string to allow you
>> to enter a literal percent character as a character-matching character,
...

> I would try two percent characters.
>
>>> fprintf('%%\n')
> %

This was for sscanf() input, not output, and I was pretty sure I had
tried it but must've had a typo I didn't recognize as

 >> s='-94%22%'
s =
-94%22%
 >> sscanf(s,'%d%%')
ans =
    -94
     22
 >>

does work (at least when one types it in correctly :) ).

I'm not sure what I did wrong now; I thought initially that would/should
work correctly, too, but as noted somehow I futzed it, apparently.

--

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com