How to compare strings and find most common values between them?
11 ビュー (過去 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 で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!