How to split string with numbers?

Asked by José on 11 Jul 2012
Latest activity Commented on by José on 11 Jul 2012

I've been reading some posts and i found some that could help me out! but for some reason it doesn't come out as i want it!

So here's the problem:

i have a string like this one '1,2,3,4;5,6,7,8;9,10,11,12' and i want to separate this string till i have 12 different strings.

i'm using this code:

g='1 2 3 4;5 6 7 8;9 10 11 12'; q=(regexp (g, ';', 'split'));

and i get this : q =

    '1 2 3 4'    '5 6 7 8'    '9 10 11 12'

but then i want to separate it once more and i change ';' to ','

w=(regexp (q(1), ' ', 'split'));

w =

    {1x4 cell}

So what am i doing wrong?

thanks for your help! José Matos

0 Comments

José

Products

No products are associated with this question.

1 Answer

Answer by Tom on 11 Jul 2012
Accepted answer
Str='1,2,3,4;5,6,7,8;9,10,11,12';
Num=str2double(regexp(Str,'\d*','match')')

1 Comment

José on 11 Jul 2012

thanks that was really quick! and helpful!!

Tom

Contact us