MATLAB: How to get statistical summary

data acquisitionData Acquisition ToolboxMATLABStatistics and Machine Learning Toolbox

Hi,
I have below cell array,
Step 34
Step 56
Double 23
Stop 123
I want to get the summation and count of each category:
Desired output:
Step 90 2
Double 23 1
Stop 123 1
Continue 0 0
Here in the above example, no continue, but in some of my cases it exists. So for each scenario, I want to get the summation & count of: Step Double Stop Continue

Best Answer

The way I'd do this is first convert your cell array to a table whose first column is of type categorical:
democell = {'Step', 34; 'Double', 56; 'Step', 23; 'Stop', 123}
demotable = table(categorical(democell(:, 1), {'Step', 'Double', 'Stop', 'Continue'}), cell2mat(democell(:, 2)), 'VariableNames', {'category', 'value'})
Your summation is then trivial:
varfun(@sum, demotable, 'GroupingVariables', 'category', 'InputVariables', 'value')