saving and retrieving string data in matlab

后端 未结 3 540
旧时难觅i
旧时难觅i 2021-01-25 00:24

Hi can any one help me in dealing with strings in MATLAB. For example, the string

A = \'A good looking boy\'

how can we store these individual

相关标签:
3条回答
  • 2021-01-25 00:54

    The most intuitive way would be using strsplit

    C = strsplit(A,' ')
    

    However as it is not available in my version I suppose this is only a builtin function in matlab 2013a and above. You can find the documentation here.

    If you are using an older version of matlab, you can also choose to get this File Exchange solution, which basically does the same.

    0 讨论(0)
  • 2021-01-25 01:07

    As found here, you could use

    >> A = 'A good looking boy';
    >> C = regexp(A,'[A-z]*', 'match')
    C = 
        'A'    'good'    'looking'    'boy'
    

    so that

    >> C{1}
    ans = 
        A
    
    >> C{4}
    ans = 
        boy
    
    >> [C{:}]
    ans =
        Agoodlookingboy
    
    0 讨论(0)
  • 2021-01-25 01:18

    You can use the simple function textscan for that:

    C = textscan(A,'%s');

    C will be a cell array. This function is in Matlab at least since R14.

    0 讨论(0)
提交回复
热议问题