MATLAB: Count numbers for a specific string, in a cell with string names and numbers

if statementstringswhile loop

My data looks like this:
departusers =
'Department A' [1]
'Department A' [1]
'Department A' [0]
'Department A' [0]
'Department B' [0]
'Department B' [1]
'Department B' [0]
'Department B' [0]
'Department C' [1]
'Department C' [0]
'Department C' [0]
'Department C' [0]
0 = Users with access to the system, which I define A
1 = Users who have used the system, which I define B
The output I need is:
Department A
A = 4
B = 2
Department B
A = 4
B = 1
Ect. It's important that the specific department name is saved with the final results.
I tried with a combination with a while and if statements, but I am having a hard time with adding up the numbers corresponding to the string names.

Best Answer

[unique_dept, ~, deptidx] = unique(departusers(:,1));
counts = accumarray([deptidx, cell2mat(departusers(:,2))+1], 1);
counts(:,1) = counts(:,1) + counts(:,2); %total number of users including those who accessed
for K = 1 : length(unique_dept)
fprintf('%s\nA = %d\nB = %d\n\n', unique_dept{K}, counts(K,:));
end