MATLAB: Reorder label

reorder

Andrei,
Thank you very much for your answer but when I put it the new made L4 introduces a row with 0 between every rows. How can I eliminate this rows? And if the matrix change of size, Have I that change anythings?
L9 =
1 1 0 0
5 5 0 0
0 5 7 7
0 0 9 11
Lp = zeros(size(L9).*[2 1]); Lp(1:2:end) = L9; Lp = bwlabel(Lp')'; L9(L9~=0)=Lp(Lp~=0); Lp =
1 1 0 0
0 0 0 0
2 2 0 0
0 0 0 0
0 3 3 3
0 0 0 0
0 0 4 4
0 0 0 0

Best Answer

L4 = zeros(size(L9).*[2 1]);
L4(1:2:end) = L9;
L4 = bwlabel(L4')';
Lp = L4(any(L4,2),:);