1

I have a cell array with one column. Each row consists of only one column. Each cell consist of a String. How can I separate the content of one column in cell array into several columns by separating the string based on space. Each string has different length. Example:

cellArrayM= {
  'hh pp'
  'my 2 ewr 3234 csdf'
  'input l 34'
  'output K 99 100'
 }

result={
   'hh'     'pp' []    []     []
   'my'     '2' 'ewr' '3234' 'csdf'
   'input'  'l' '34'  []      []
   'output' 'k' '99'  '100'   []
         }
ryh12
  • 357
  • 7
  • 18

2 Answers2

1

You can do it this way:

x = cellfun(@(x) strsplit(x), cellArrayM, 'uniformoutput', 0);
result = cell(numel(x), max(cellfun(@numel, x)));
for k = 1:numel(x)
    result(k, 1:numel(x{k})) = x{k};
end
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
-1

You can do like this:

splitCellArray = regexp(cellArrayM,' ','split')
techdreams
  • 5,371
  • 7
  • 42
  • 63
Dong
  • 1