MATLAB: How to find the rows with the same values, and to merge those

concatenatefind the same valuematrix

I would want to know a way to find the rows having the same value in the first column (id), and combine those rows together.
Suppose I have the matrix A;
A = [1 2 3 4;
1 5 6 0;
2 2 3 4;
2 5 6 0;
2 6 7 8;
3 1 2 3;
4 1 2 3]
What I want to do is to find the rows with same ids (1st column), and merge their features (other columns). In this case, I need the following matrix.
A = [1 2 3 4 5 6 0 0;
2 2 3 4 5 6 7 8;
3 1 2 3 0 0 0 0;
4 1 2 3 0 0 0 0];

Best Answer

Sounds like a homework assignment (tag it as homework if that's true), so how about I just get it started for you:
A = [1 2 3 4;
1 5 6 0;
2 2 3 4;
2 5 6 0;
2 6 7 8;
3 1 2 3;
4 1 2 3]
% Find unique numbers in the first column.
uniqueCol1 = unique(A(:,1))
% Find out how many times each number occurs.
counts = hist(A(:,1), uniqueCol1)
% Find out how big our output matrix needs to be, and create it.
rows = length(uniqueCol1);
columns = 3 * max(counts);
outputA = zeros(rows, columns, 'int32');
% Assign first column
outputA(:,1) = uniqueCol1
You can finish it.