hei*_*nst 3 string matlab octave
我有一段很长的段落,想知道其中最出现的词。有人可以为此指出正确的方向吗?任何示例和解释都将有所帮助。谢谢!
这是一种非常MATLAB-y的方法。我试图清楚地命名变量。玩每一行,检查结果以了解其工作原理。主力功能:unique
和hist
% First produce a cell array of words to be analyzed
paragraph_cleaned_up_whitespace = regexprep(paragraph, '\s', ' ');
paragraph_cleaned_up = regexprep(paragraph_cleaned_up_whitespace, '[^a-zA-Z0-9 ]', '');
words = regexpi(paragraph_cleaned_up, '\s+', 'split');
[unique_words, i, j] = unique(words);
frequency_count = hist(j, 1:max(j));
[~, sorted_locations] = sort(frequency_count);
sorted_locations = fliplr(sorted_locations);
words_sorted_by_frequency = unique_words(sorted_locations).';
frequency_of_those_words = frequency_count(sorted_locations).';
Run Code Online (Sandbox Code Playgroud)