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
Azzi Abdelmalek 2014 年 4 月 16 日
編集済み: Azzi Abdelmalek 2014 年 4 月 16 日

0 投票

str={'ABC DEF';'GHI JKL';'MNO PQR' }
out=cellfun(@strsplit,str,'un',0)
out=reshape([out{:}],2,[])'

4 件のコメント

Cl
Cl 2014 年 4 月 16 日
Thank you, unfortunately I get the error
Error using reshape
Product of known dimensions, 2, not divisible into total number of elements, 23153.
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 16 日
That means your data do not look like str
Cl
Cl 2014 年 4 月 16 日
編集済み: Cl 2014 年 4 月 16 日
Your example works, but not with my data, what is the 'un',0 bit?
Azzi Abdelmalek
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
Image Analyst 2014 年 4 月 16 日

0 投票

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'

カテゴリ

タグ

質問済み:

Cl
2014 年 4 月 16 日

回答済み:

2014 年 4 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by