Search code examples
stringmatlabdoublestring-parsing

string to numerical, withouth spaces


In MATLAB if I have a string like:

 a='0.424870551E+03-0.100113019E+03 0.470220758E+03';

If I use

 b=str2num(a);

I get

 b =324.7575  470.2208;

That is, MATLAB performed the operation for the first two numbers rather than give a 3 column vector.

Is there a possibility to convert a into a 3 column vector without using textscan?

This might seem as a pretty easy thing; I didn't found no further information in the str2num documentation, so that's the reason why I'm asking,


Solution

  • Specify the format correctly and it will be interpreted right even without the space:

    >> sscanf(a,'%E')
    ans =
      424.8706
     -100.1130
      470.2208