Prev: POKER PREDICTOR help
Next: Help with lsqcurvefit
From: Fangjun Jiang on 30 Jul 2010 15:59 In this particular case, a=str2num(line) a = 1 -1 5 5 -3 Not sure if it will work for all your strings. "Mike " <mikejcunningham(a)gmail.com> wrote in message <i2v9hn$d9f$1(a)fred.mathworks.com>... > I am having an issue reading in both negative and positive numbers from a string. > > I have a string: > > line = '1 -1 5 5 -3' > > and I want to read in each number... > > I'm using regexp but cannot get it to read both negative and positive numbers > > I have > > x = regexp(line,'[-]\d+','match') > > which returns only the negative numbers > > or doing > > x = regexp(line,'\d+','match') > > returns all numbers but positive. > > I don't understand the expressions in regexp very well, thus I can't get this to work. > > Thanks for any help! > -- > Mike
From: reza on 30 Jul 2010 16:08 And yet another way to this: eval(['[' line ']']) /m On Jul 30, 3:35 pm, "Mike " <mikejcunning...(a)gmail.com> wrote: > I am having an issue reading in both negative and positive numbers from a string. > > I have a string: > > line = '1 -1 5 5 -3' > > and I want to read in each number... > > I'm using regexp but cannot get it to read both negative and positive numbers > > I have > > x = regexp(line,'[-]\d+','match') > > which returns only the negative numbers > > or doing > > x = regexp(line,'\d+','match') > > returns all numbers but positive. > > I don't understand the expressions in regexp very well, thus I can't get this to work. > > Thanks for any help! > -- > Mike
|
Pages: 1 Prev: POKER PREDICTOR help Next: Help with lsqcurvefit |