How to compare strings and find most common values between them?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 1 de Dic. de 2013
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 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!