MATLAB: Neat stacking of array and cell array

cell arrayneatly stuck upstack up

Hi all
i have this 3×2 cell array:
6x1 cell 1x1 cell %a

1x1 cell 1x1 cell %b

[] 1x1 cell %c

i want to stack up the cell array in this way:
6x1 cell
1x1 cell %a
1x1 cell
1x1 cell %b
[]
1x1 cell %c
then i want to remove the empty cell and expand the 5×1 cell in a matrix.
i have tried with vertcat but it doesn't keep the order…
Thank you for the help
Regard!!

Best Answer

Where C is your cell array:
D = C.';
D(cellfun(@isempty,D)) = []; % not actually required: try without it!
M = vertcat(D{:})