MATLAB: Outputting cumulative sum for Cell array with strings and numbers

cell arraysstrings

Cell1={
'A1' 5
'A2' 1
'A3' 2
'A4' 4
'A5' 1
'B1' 2
'B2' 6
'B3' 17
'B4' 8
'B5' 3
'C1' 7
'C2' 8
'D1' 1
.
.
.
};
I have a cell Cell1 which has varying row length. How can I say for example; for all As Bs Cs Ds Es etc .... count the values in column two. In the end, I would like to have an output like this
'A' 13
'B' 36
'C' 15
'D' 1
etc...

Best Answer

Cell1={
'A1' 5
'A2' 1
'A3' 2
'A4' 4
'A5' 1
'B1' 2
'B2' 6
'B3' 17
'B4' 8
'B5' 3
'C1' 7
'C2' 8
'D1' 1};
S = regexp(Cell1(:,1),'^[A-Za-z]+','match');
S = [S{:}]';
[a,~,c] = unique(S);
out = [a num2cell(accumarray(c,cell2mat(Cell1(:,2))))];