How do I find and display the most frequent word in ALL sentences combined?

2 views (last 30 days)
if I have 5 sentences (s1, s2, s3, s4, s5) and i put them all into one string (s) using:
s=[s1 ' ' s2 ' ' s3 ' ' s4 ' ' s5]
How would I go through all the words in each sentence to ascertain and display the most frequent word in ALL sentences?

Answers (2)

Matt J
Matt J on 9 Nov 2013
Edited: Matt J on 9 Nov 2013
I would use MAT2CELL to split the words in 's' into individual cells. Then I would use UNIQUE and HISTC to count repetitions.

Walter Roberson
Walter Roberson on 9 Nov 2013
regexp() with the 'split' option to break the string into words. Then you can unique() the resulting cell array, and examine the third output of unique() to determine how many times each value occurred.

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!