I have a 4×4 cell array C, which
C= {
[1] [3] [6] [ ];
[2] [ ] [ ] [8];
[ ] [4] [ ] [9];
[ ] [5] [7] [ ]}
I want to generate a new cell array D which give me
D = {[1;2], [3], [4;5],[6],[7],[8;9]}
basically I want to 1. combine the adjacent non empty cell in each column vertically and 2. output the new cell array D contains the result.
You can use this. I’ve used bwlabel from the imaging toolkit:
lensis now a logical array indicating if any slot in C is empty or not. Now we can constructDby treating each column inlensas a 1 x whatever binary image, and seek regions usingbwlabel(). Finally we put the regions into D.