MATLAB: Create columns with no zero sequentially elements of a vector

arraymatrixvector

I have a vector A=[4,2 3 2 2 0 0 1 2 2 0 0 1 2 3] and I am trying to create columns in new matrix with no zero sequentially elements, with a loop without success.Β1=[4,2 3 2 2] B2=[1 2 2] etc
I want to have a column with elements of A and when I find zero to create another column. Do you believe that it is feasible?

Best Answer

This is very easy with the Image Processing Toolbox. Simply use bwlabel() (and regionprops() if you're going to have some unknown number of regions rather than exactly 3).
A=[4 2 3 2 2 0 0 1 2 2 0 0 1 2 3]
labeled = bwlabel(A)
B1 = A(labeled==1)
B2 = A(labeled==2)
B3 = A(labeled==3)
Do you have that toolbox?