Prev: In an assignment A(;) = B, the number of elements in A and B must be the same
Next: Pinv causing crash
From: George34 Dampf on 3 Dec 2009 12:57 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 3 Dec 2009 14:02 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 3 Dec 2009 19:03 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 6 Dec 2009 13:33 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 6 Dec 2009 16:16
ok, got it... it's c=s(isspace(s) | isletter(s) ) |