How to split the name in to two cells
1 view (last 30 days)
Show older comments
Kanakaiah Jakkula
on 28 Sep 2017
Edited: Cedric Wannaz
on 28 Sep 2017
Hi,
I have a cell matrix:
'56' 'mat find false' '89 mm' 'mat 96 kl'
I want to split:
- 'mat find false' --> 'mat' 'find false' (one cell to two cells)
- 'mat 96 kl' -->'mat' '96 kl'
desired Output:
'56' 'mat' 'find false' '89 mm' 'mat' '96 kl'
Many thanks in advance,
0 Comments
Accepted Answer
Cedric Wannaz
on 28 Sep 2017
Edited: Cedric Wannaz
on 28 Sep 2017
Or regexp-based: if
C = {'56', 'mat find false', '89 mm', 'mat 96 kl'} ;
then
result = regexp(C, '(mat)?\s?(.*)', 'tokens', 'once') ;
result = [result{:}] ;
result(cellfun(@isempty, result)) = [] ;
outputs:
result =
1×6 cell array
'56' 'mat' 'find false' '89 mm' 'mat' '96 kl'
2 Comments
Cedric Wannaz
on 28 Sep 2017
Edited: Cedric Wannaz
on 28 Sep 2017
Thanks Jan!
I'll have to frame the following on my wall:

See Also
Categories
Find more on R Language in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!