MATLAB: How to split an array with a periodic set of elements as it reaches to the maximum elements

array manipulationsplit

lets say i have an array with periodic set of elements such as below:
A=[2 2 2 3 3 4 4 5 5 5 1 1 1 2 2 2 2 3 3 4 4 4 4 5 5 1 1 2 3 3 4 4 4 5 5];
i want to split Array A in to 3 separate arrays(in this case) as it reach to element 5 as below:
B1=[2 2 2 3 3 4 4 5 5 5];
B2=[1 1 1 2 2 2 2 3 3 4 4 4 4 5 5];
B3=[1 1 2 3 3 4 4 4 5 5];
i greatly appreciate your help
thank you

Best Answer

B = mat2cell(A(:)',1,diff(find([true,diff([A(:)'== 5,0]) == -1])));