finding unique phrases and their frequency in a cell array
Show older comments
Hi,
I usually deal with numbers but never with text. I have a cell array of phrases(attached the mat file) . I want to know what are these uniques phrases and the frequency of each phrase (how many time it appears). Any help would be greatly appreciated.
Accepted Answer
More Answers (1)
Danielle Leblance
on 14 Apr 2020
Edited: Danielle Leblance
on 14 Apr 2020
0 votes
1 Comment
Star Strider
on 14 Apr 2020
Your file did not have blank cells.
Experiment with this:
D = load('matlab.mat');
nbEmployees = D.nbEmployees;
nbEmployees = nbEmployees(cellfun(@(x)~isempty(x), nbEmployees),:);
[uE,~,ix] = unique(nbEmployees);
tally = accumarray(ix, 1);
Out = table(uE, tally, 'VariableNames',{'Phrase','Frequency'})
That runs without error, and assumes that ‘blank’ elements are ‘empty’ elements.
.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!