MATLAB: Remove empty cells (of a m*n cell)

cell arrays

Hello,
You could find attached a cell. My aim is to remove all empty cells in order to have a 10×14 cell.
I've try the following function :
Cell=(cellfun('isempty', Cell));
Cell(idx) = [];
But I got a 1×140 cell (instead of 10×14)
Thanks in advance for your help,
Marie

Best Answer

load Cell
Step_40C_2
NE = ~cellfun(@isempty,Step_40C_2);
temp = arrayfun(@(C) Step_40C_2(NE(:,C),C), 1:size(Step_40C_2,2), 'uniform', 0);
Cell = horzcat(temp{:})
Or
load Cell
Step_40C_2
NE = ~cellfun(@isempty,Step_40C_2);
Cell = reshape(Step_40C_2(NE), [], size(Step_40C_2,2))