%% Count Labels in Tables and Datastores
% Create a table of characters with two variables. The first variable Type1 contains instances of the letters P, Q, and R. The second variable Type2 contains instances of the letters A, B, and D.

tbl = table(["P" "R" "P" "Q" "Q" "Q" "R" "P"]', ...
    ["A" "B" "B" "A" "D" "D" "A" "A"]',...
    'VariableNames',["Type1","Type2"]);

% Count how many times each letter appears in each of the table variables.

cnt = countlabels(tbl,'TableVariable','Type1')
cnt = countlabels(tbl,'TableVariable','Type2')

%
% Create an ArrayDatastore object containing the table.

ads = arrayDatastore(tbl,'OutputType','same');

% Count how many times each letter appears in each of the table variables.

cnt = countlabels(ads,'TableVariable','Type1')
cnt = countlabels(ads,'TableVariable','Type2')

% Copyright 2020 The MathWorks, Inc.