Parsing a string into a vector

View: New views
3 Messages — Rating Filter:   Alert me  

Parsing a string into a vector

by AlexG1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I need to parse a string containing numbers (e.g. '1 2 3 4 5') into a numeric vector.
In Matlab I simply used the strread() function, but I don't see any equivalent for it in Octave. I've tried using strtok() but I can't get it work properly, and it's pretty ugly anyway.
Can someone please post a code sample to help me with this?

Thanks,

Alex

Re: Parsing a string into a vector

by Søren Hauberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

søn, 08 02 2009 kl. 03:37 -0800, skrev AlexG1:
> I need to parse a string containing numbers (e.g. '1 2 3 4 5') into a
> numeric vector.
> In Matlab I simply used the strread() function, but I don't see any
> equivalent for it in Octave. I've tried using strtok() but I can't get it
> work properly, and it's pretty ugly anyway.

Is 'str2num' what you want?

str2num ('1 2 3 4 5')
ans =

   1   2   3   4   5

Søren

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Parsing a string into a vector

by AlexG1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Søren Hauberg wrote:
Is 'str2num' what you want?

str2num ('1 2 3 4 5')
ans =

   1   2   3   4   5

Søren
Exactly that, thanks. I actually stumbled over this fubnction but the help description made me think it could only convert one number at a time.