MATLAB: How to create a sub-matrix from a matrix with repeated values in a column

MATLABrepeated valuessub matrixunique

I'm having troubles when I try to create a sub-matrix from a matrix with a column with repeated values.
For example, let consider the matrix A:
A = [1 6 13 34 26 27;
1 7 14 35 25 28;
1 8 15 36 24 29;
2 9 16 37 23 30;
2 10 17 38 22 31;
3 11 3 18 21 32; ]
I would like to obtain, not for a specific matrix A like in this example but for any given A, the sub-matrix B, C and D bellow:
B = [ 1 6 13 34 26 27;
1 7 14 35 25 28;
1 8 15 36 24 29; ]
C = [2 9 16 37 23 30;
2 10 17 38 22 31; ]
D = [3 11 3 18 21 32; ]
Thank you very much for your help.

Best Answer

Use the accumarray function:
[Au,~,ic] = unique(A(:,1));
Outc = accumarray(ic, (1:size(A,1))', [], @(x){A(x,:)});
producing:
B = Outc{1}
C = Outc{2}
D = Outc{3}
B =
1 6 13 34 26 27
1 7 14 35 25 28
1 8 15 36 24 29
C =
2 9 16 37 23 30
2 10 17 38 22 31
D =
3 11 3 18 21 32
The unique call (although uniquetol would be more generally applicable), is not strictly necessary here because ‘A(:,1)’ are consecutive integers. However since that may not always be the situation, I included it to make the code more robust.