From: Armin Mueller on 22 Apr 2010 15:12 Hi all, what is the best way to parse a string like this: -50 mm;0 mm;250 mm I would like to get the three coordinates as numbers, e.g. x = -50 y = 0 z = 250 I played around with sscanf(), but didn't get it working. Thank you very much for any hint! Armin
From: us on 22 Apr 2010 15:24 Armin Mueller <arm.in(a)web.de> wrote in message <hqq736$a34$1(a)news2.rz.uni-karlsruhe.de>... > Hi all, > > what is the best way to parse a string like this: > > -50 mm;0 mm;250 mm > > I would like to get the three coordinates as numbers, e.g. > > x = -50 > y = 0 > z = 250 > > I played around with sscanf(), but didn't get it working. > > Thank you very much for any hint! > Armin one of the solutions s='50 mm;0 mm;250 mm'; n=strread(s,'%f','whitespace',['m;']) %{ % n = 50 0 250 %} us
From: Walter Roberson on 22 Apr 2010 15:34 Armin Mueller wrote: > Hi all, > > what is the best way to parse a string like this: > > -50 mm;0 mm;250 mm > > I would like to get the three coordinates as numbers, e.g. > > x = -50 > y = 0 > z = 250 str2num(char(regexp(String, '-?\d+', 'match'))) will give all of them, as numbers, in a single pass.
From: Armin Mueller on 22 Apr 2010 16:15 us wrote: > one of the solutions [...] Urs, you are brilliant. Thank you! - Armin
From: Jan Simon on 23 Apr 2010 06:47 Dear Armin! > what is the best way to parse a string like this: > -50 mm;0 mm;250 mm > > I would like to get the three coordinates as numbers, e.g. > x = -50 > y = 0 > z = 250 > > I played around with sscanf(), but didn't get it working. To be complete here the SSCANF method: Str = '-50 mm; 0 mm; 250 mm'; X = sscanf(Str, '%d mm;', 3) ==> X = [-50; 0; 250] Good luck, Jan
|
Pages: 1 Prev: syntax to use Parfor for "for loops " Next: append data in uitable |