find the count of items in the the table column in matlab

To find the count of items in a specific column of a table in MATLAB, you can use the unique function to extract the unique values in that column, and then use the histcounts function to count the frequency of each unique value. Here's an example:

main.m
% create a sample table
t = table({'A'; 'B'; 'C'; 'A'; 'B'; 'A'; 'C'}, [10; 20; 30; 40; 50; 60; 70], 'VariableNames', {'Letters', 'Numbers'});

% extract the unique values in the 'Letters' column
uniqueValues = unique(t.Letters);

% count the frequency of each unique value
counts = histcounts(t.Letters, [''; uniqueValues]);

% display the results
disp(table(uniqueValues, counts', 'VariableNames', {'Letters', 'Count'}));
424 chars
12 lines

This will output the following table:

main.m
  Letters    Count
_________    _____

''             0  
'A'            3  
'B'            2  
'C'            2  
115 chars
8 lines

In this example, the 'Letters' column of the t table contains 3 'A' values, 2 'B' values, and 2 'C' values.

gistlibby LogSnag