MATLAB: Summing values for duplicate rows and columns

matrix manipulationvector

I have a vector of rows, columns, and values that I will use to create a sparse matrix:
rows = [1 2 3 1]; columns = [1 1 2 1]; values = [10 50 25 90];
Notice the duplicates:
(1,1) 10 (1,1) 90
What I need is to eliminate (row,column) duplicates by summing the values corresponding to these duplicates for each.
The solution in the current example is:
rows = [1 2 3]; columns = [1 1 2]; values = [100 50 25];
What operation on the three initial vectors reduce them to the solution above?

Best Answer

A = accumarray([[1 2 3 1]',[1 1 2 1]'],[10 50 25 90]',[],[],[],1);