MATLAB: Cumulative sum of groups

cumsumgroup byMATLAB

I need the cumlative sum of the second column of Data grouped by (or reset at each change in) the first column of Data please:
Data = [[1;1;1; 2;2;2; 3;3;3], [1;0;1; 0;1;1; 0;1;0]]
Answer = [Data, [1;1;2; 0;1;2; 0;1;1]]
Data =
1 1
1 0
1 1
2 0
2 1
2 1
3 0
3 1
3 0
Answer =
1 1 1
1 0 1
1 1 2
2 0 0
2 1 1
2 1 2
3 0 0
3 1 1
3 0 1

Best Answer

>> data = [1,1;1,0;1,1;2,0;2,1;2,1;3,0;3,1;3,0];
>> C = accumarray(data(:,1),data(:,2),[],@(v){cumsum(v)});
>> [data,vertcat(C{:})]
ans =
1 1 1
1 0 1
1 1 2
2 0 0
2 1 1
2 1 2
3 0 0
3 1 1
3 0 1