string - 如何知道段落中出现最多的词是什么? (Matlab)

标签 string matlab octave

我有一个很大的段落,想知道里面出现最多的词是什么。谁能用这个给我指出正确的方向?任何示例和解释都会有所帮助。谢谢!

最佳答案

这是一种非常适合 MATLAB 的方法。我试图清楚地命名变量。玩每一行并检查结果以了解它是如何工作的。主力函数:uniquehist

% 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).';

关于string - 如何知道段落中出现最多的词是什么? (Matlab),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13592390/

相关文章:

linux - 从源代码构建 Octave 包

MATLAB 在两者之间插入值

arrays - 查找分组在数组中的特定零点 - matlab

plot - 打印绘图时 Octave 崩溃

matlab - 成本函数,sum(x)和ones(1,length(x)) *x有什么区别?

matlab - 随机排列矩阵行,保持相同值的行相邻

c++ - 为什么 VS UnitTesting 框架中的 Assert::AreEqual 不能与 std::string 一起使用?

javascript - 在 Javascript 中,如何转换字符串以便它可以用于调用属性?

java - 既然我们已经有了 StringBuilder,为什么还要使用 StringJoiner?

c - tolower 用于 C 风格的字符串