strsplit: undefined function for input type 'char'

前端 未结 1 1767
北荒
北荒 2020-12-15 22:59

I have a <20x1> cell array and each of them stores some data in the form of a string (as it appears to me!!!). I want to access each element of the cell as an individual

相关标签:
1条回答
  • 2020-12-15 23:08

    My guess is that you're using a version of Matlab prior to R2013a. Despite the fact that they are generic functions and should have bee added ages ago, strsplit and strjoin were only added in this most recent version.

    There are several ways you can get around not having access to strsplit if all you want to do is split a string into words. If all of your whitespaces are simple spaces you can just use strread like this:

    strread(line,'%s','delimiter',' ')
    

    However, textscan should be more robust:

    textscan(line,'%s')
    

    Using regexp should also be robust, but will likely be slower:

    regexp(line,'\s+','split')
    

    All of these return outputs as cell arrays of strings (your words), just like strsplit. The output from textscan is transposed relative to the others.

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