How to compare strings and find most common values between them?
3 次查看(过去 30 天)
显示 更早的评论
So I have a series of strings stored in a cell array, each of which occupies it's own element in that cell array, which for now we will call "tagstrings". Some of these strings are just repeats of each other, and they are not all the same or the same length. "tagstrings" looks something like this;
I ate 34 slices of pizza
I ate 34 slices of pizza
I ate 34 slices of pizza
I ate 35 slices of pizza
I ate 89 slices of cheese pizza
I want to be able to take each of those strings, find the terms and/or words that appear most commonly, then collect them all into one single string that summarizes the most common information word by word. I would also like to limit the term or character length of the ending result string. the order in which the terms appear in the end is not important to me, but would be awesome if we could get that to happen.
In the example above, the code I desire would see that "35" and "89" and "cheese" for example are not very common, and would output a string that excludes these terms. I've tried separating the strings into cell arrays which deconstruct each string into its own cell array word by word using the strread command, but I didn't know what to do after this and it just got more complicated.
0 个评论
回答(1 个)
Walter Roberson
2013-12-1
splitphrases_cells = regexp(YourCellStringArray, '\s+', 'split');
splitphrases = horzcat(splitphrases_cell{:});
Now everything is word by word in one cell array of strings, ready for you to count.
Hint: Read all of the possibilities of unique()
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!