"ian johnston" <iano1213@gmail.com> wrote in message <i93evd$9nu$1@fred.mathworks.com>...
> Good day Matlab Community,
>
> I have 2 problems I'd like some help with please:
>
> Matrix A and B is given to me:
>
> A =
> [ 2 1
> 3 1
> 3 2
> 1 3
> 1 2
> 2 3 ]
>
> B = [ 10 42
> 38 67
> 22 88
> 5 90
> 29 45
> 3 11]
>
> The first problem I'm faced with is firstly concerned with matrix A. How can A be grouped where elements in rows are repeated? So the desired result would be is:
>
> Grouped_A = [ 2 1 1 2;
> 3 1 1 3;
> 3 2 2 3]
>
> The second problem is trying to use the 'Grouped_A' matrix to also group its corresponding rows in matrix B. So the result I'm trying to get is:
>
> Grouped_B = [ 10 42 29 45;
> 38 67 5 90;
> 22 88 3 11]
>
> best,
> Ian
          
[~,~,n] = unique(sort(A,2),'rows');
[~,n] = sort(n);
GA = [A(n(1:2:end),:),A(n(2:2:end),:)];
GB = [B(n(1:2:end),:),B(n(2:2:end),:)];
Roger Stafford
