Feed on
Posts
Comments

to split a delimited string in matlab, you can use the ‘regexp’ function.  for instance, if i’ve got a string named tline that’s been tab-delimited, i can parse it using:

 >> parts = regexp(tline,’\t’,’split’);


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

6 Responses to “split a delimited string in matlab”

  1. on 23 Feb 2009 at 1:03 pm srividhya

    hi..
    i have a string..
    a=’university’
    i want to split this into uni,ver,sity..
    how can i do this in matlab..
    please reply for me..am badly in need of this solution.
    thank u so much…..

  2. on 26 Feb 2009 at 5:55 pm Peter

    Hey Lawrence,

    1) I really like your photo-navigation! That’s quite creative.

    2) When you are giving help on a particular application such as Matlab, please list the version that you are using. In v6.5.2, I get “Invalid option for regexp: split.” I found that my version of regexp only accepts two arguments anyway.

    Thanks.

  3. on 26 May 2009 at 9:28 am Geert

    Hi there,

    Thanks for this! I was driving me crazy that there was no simple solution for this in Matlab. There are some functions around but none as efficient as yours. And, I could not find this in the Matlab reference (R2006b). The ’split’ option is nowhere to be found.

    GNU Octave has the ’split’ function that does just this and this was giving me headaches when porting my code to Matlab.

    Thanks again.

  4. on 20 Aug 2009 at 2:42 pm John

    In matlab you have to use the regexp function with the 3rd, optional argument set to ’split’. It’s silly, but that’s how they chose to do it. Full syntax:

    TargetVar = regexp(’(any string)’,'(delimiter)’,’split’);

    The output is a cell array (maybe two deep, I don’t remember) with the entries you want. Type help regexp.

  5. on 01 Apr 2010 at 2:22 pm yashu

    hii.. want to divide kanada word into single characters using matlab code .how should i write the code ??’

    plz send me the code ……..
    tanx alot ………:)

  6. on 27 May 2010 at 8:41 am Ramon Fincken

    Excellent, thanks. The answer is indeed a cell array:

    I have filenames like
    A__somethinghere.png

    To get the ‘A’ I use this in my loop:
    temp = dirList(x).name;
    temp2 = regexp (temp,’__’,’split’);
    imagegroup = temp2{1,1};

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.