-->

确定单元阵列的每个单词的出现次数(Determining the number of occurre

2019-10-21 10:03发布

我有话巨大的载体,我想只有唯一码字的矢量,并为每个单词的频率。 我已经尝试过histhistc但它们对于数值。 我知道功能tabulate ,但它给人的话有些“(例如,这变成‘这个’)。 如果你有任何想法如何做到这一点MATLAB这将是巨大的。 谢谢

Answer 1:

你在正确的轨道上! 只需使用unique先准备数字输入hist 。 诀窍是,通过返回的字occurence IDS unique可以被用作输入hist功能,这样你就可以得到数没有显式for循环:

words = {'abba' 'bed' 'carrot' 'damage' 'bed'};
[unique_words, ~, occurrences] = unique(words);
unique_counts = hist(occurrences, 1:max(occurrences));

这产生了:

>> unique_words 
    'abba'    'bed'    'carrot'    'damage'

>> unique_counts
     1     2     1     1


文章来源: Determining the number of occurrences of each word in cell array