How to split the name in to two cells
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Cedric
2017-9-28
编辑:Cedric
2017-9-28
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 个评论
Jan
2017-9-28
As usual I mention that cellfun('isempty') is faster than cellfun(@isempty), because it does not call a Matlab function in a loop, but checks the emptiness inside the Mex function.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!