MATLAB: Sum specific rows of an array

arraymatrix array

Hi,
I have an array like:
0.2 2 3
1 3 4
1 4 6
0.8 4 6
2 5 1
1 6 2
0.4 6 2
Now I want to code that MATLAB sums up the values of the 1st column in the rows where the value of the 2nd and 3rd column match.
So the result should look like this below:
0.2 2 3
1 3 4
1.8 4 6
2 5 1
1.4 6 2
I hope someone can help me, thank you!

Best Answer

A = [0.2 2 3
1 3 4
1 4 6
0.8 4 6
2 5 1
1 6 2
0.4 6 2];
[a,~,c] = unique(A(:,2:3),'rows','stable');
out = [accumarray(c,A(:,1)),a];