read cell array and split into one cell array of multiple rows
Show older comments
Hello,
I have a cell array with strings, for example:
names =
2×1 cell array
{'A B C D E F G H '}
{'I J ' }
I want them in an array like this one:
KNAME =
10×1 cell array
{'A'}
{'B'}
{'C'}
{'D'}
{'E'}
{'F'}
{'G'}
{'H'}
{'I'}
{'J'}
I do something too complicated that works but I am guessing there is an easier solution to this
Accepted Answer
More Answers (1)
Omer Yasin Birey
on 29 Jan 2019
name{1,:} = {'A B C D E F G H'};
name{2,:} = {'J '};
str = string(name);
C = arrayfun( @(x) strsplit( x, ' ' ), str, 'UniformOutput', false );
conc = horzcat(C{:})';
cellA = cellstr(conc);
2 Comments
FM
on 29 Jan 2019
Omer Yasin Birey
on 29 Jan 2019
Yes FM, Stephen's answer can do what you want.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!