问题
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' []
}
回答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
回答2:
You can do like this:
splitCellArray = regexp(cellArrayM,' ','split')
来源:https://stackoverflow.com/questions/45292709/separating-cell-array-into-several-columns-matlab