MATLAB: Finding and counting of identical rows in a matrix

MATLABoctave

hello together,
I have to find the identical rows or identical lines in a matrix and sum the time values of these rows in the first column. At the end I have to create a new matrix and write only one of the identical rows and delete the rest identical rows. And I have to keep not identical rows for example
Matrix:
1 300 3500 500 6000
3 200 3000 500 6500
5 150 2500 450 6000
8 400 2000 550 5500
5 200 3000 500 6500
9 150 2500 450 6000
2 200 3000 500 6500
...
2nd, 5th and 7th rows are identical except 1st column . Then I have to add the corresponding values in the first column or 3 + 5 + 2 = 10. as well as 3rd and 6th, so 5 + 9 = 14
I have to write one of the identical rows and not identical rows. The identical lines occur more than 2 times. Matrix consists of many rows eg. 1000. The new matrix looks like this:
1 300 3500 500 6000
10 200 3000 500 6500
14 150 2500 450 6000
8 400 2000 550 5500
how can I realize this in Octave? Would anyone have an idea?
Thank you very much

Best Answer

For Octave?
M = [ 1 300 3500 500 6000
3 200 3000 500 6500
5 150 2500 450 6000
8 400 2000 550 5500
5 200 3000 500 6500
9 150 2500 450 6000
2 200 3000 500 6500];
[a,b,c] = unique(M(:,2:end),'rows','first');
[~,i] = sort(b);
[~,ii] = sort(i);
out = [accumarray(ii(c),M(:,1)), a(i,:)];
Here use Octave 5.1.0