From: George34 Dampf on
hi there,
i have to parse a string with a format like that : 'xx45 yy-23.3 aa4 bb4.3'
and i want to store the data in two vectors:
v1 = [ xx, yy, aa, bb ] and v2 = [ 45, -23.3, 4, 4.3 ]

but i can't manage to split the characters form the numeric values...
how can i do this?
thanx!
From: dpb on
George34 Dampf wrote:
> hi there,
> i have to parse a string with a format like that : 'xx45 yy-23.3 aa4 bb4.3'
> and i want to store the data in two vectors:
> v1 = [ xx, yy, aa, bb ] and v2 = [ 45, -23.3, 4, 4.3 ]
>
> but i can't manage to split the characters form the numeric values...
> how can i do this?
> thanx!

>> s='xx45 yy-23.3 aa4 bb4.3';
>> c=s(isletter(s))
c =
xxyyaabb
>> n=s(~isletter(s))
n =
45 -23.3 4 4.3
>>

--
From: dpb on
dpb wrote:
> George34 Dampf wrote:
>> hi there,
>> i have to parse a string with a format like that : 'xx45 yy-23.3 aa4
>> bb4.3'
>> and i want to store the data in two vectors:
>> v1 = [ xx, yy, aa, bb ] and v2 = [ 45, -23.3, 4, 4.3 ]
>>
>> but i can't manage to split the characters form the numeric values...
>> how can i do this?
>> thanx!
>
> >> s='xx45 yy-23.3 aa4 bb4.3';
> >> c=s(isletter(s))
> c =
> xxyyaabb
> >> n=s(~isletter(s))
> n =
> 45 -23.3 4 4.3
> >>

Or, perhaps more closely to your wishes...

>> [c,n]=strread(s,'%2s%f')
c =
'xx'
'yy'
'aa'
'bb'
n =
45.0000
-23.3000
4.0000
4.3000
>>

As long as the nonnumeric character string is fixed you can use the
field width to do the separation for you from the numeric field which is
terminated by the blank.

Of course if this formatting changes, the above will break...

--
From: George34 Dampf on
thanks a lot!
but the data format changes, so i can't use strread(s,'%2s%f')...

if i use c=s(isletter(s)) i get c = xxyyaabb,
but how can i get c = 'xx yy aa bb' ?
From: George34 Dampf on
ok, got it...
it's c=s(isspace(s) | isletter(s) )