Split string in cells to two cells
이전 댓글 표시
I have about 2000 cells all contained under one name i.e. names=2000x1 cell. Each cell has an entry such as 'ABC DEF'. I need to split these into two cells so that names=2000x2 cell with e.g. {1,1}='ABC' {1,2}='DEF'. Is this possible?
If not, is there any other way I can create a 'vector' (I know that's not the right word because I'm working with strings, but not sure how to phrase it and hope this makes people understand) of the first parts ('ABC') and then another vector of the second parts ('DEF')?
답변 (2개)
Azzi Abdelmalek
2014년 4월 16일
편집: Azzi Abdelmalek
2014년 4월 16일
str={'ABC DEF';'GHI JKL';'MNO PQR' }
out=cellfun(@strsplit,str,'un',0)
out=reshape([out{:}],2,[])'
댓글 수: 4
Cl
2014년 4월 16일
Azzi Abdelmalek
2014년 4월 16일
That means your data do not look like str
Azzi Abdelmalek
2014년 4월 16일
편집: Azzi Abdelmalek
2014년 4월 16일
I used an example like you described your data, it looks like your description is incomplete. 'un',0 means UniformeOutput, false
Image Analyst
2014년 4월 16일
See John D'Errico's allwords. It does that. http://www.mathworks.com/matlabcentral/fileexchange/27184-allwords
str = 'See John DErricos allwords. It does that.'
caWords = allwords(str) % Make cell array of words.
In Command Window:
str =
See John DErricos allwords. It does that.
caWords =
'See' 'John' 'DErricos' 'allwords' 'It' 'does' 'that'
카테고리
도움말 센터 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!