0

我创建了一个 matlab 程序来在文本文件中查找单词二元组及其频率。为此,我使用 textread 函数创建了一个字符串元胞数组:

unigrams = textread('file.txt','%s');

但我也希望从我的单元格数组中省略一堆单词,如'to'、'the'、'is'、'or'等以及特殊字符'#'、'$'、'&'和'%' . 有没有办法在从原始文件中读取单词时排除这些单词。

谢谢。

4

1 回答 1

1

您可以setdiff 阅读文本后使用删除不需要的单词:

unigrams = {'I' 'like' 'this' 'or' 'that' 'Here' 'are' 'some' 'symbols' '#' '$' '&'}
setdiff(unigrams, {'the', 'is' 'or' '#' '$' '&'}, 'stable')

unigrams = 
  Columns 1 through 8
    'I'   'like'   'this'   'or'   'that'   'Here'   'are'   'some'
  Columns 9 through 12
    'symbols'   '#'   '$'   '&'
ans = 
    'I'   'like'   'this'   'that'   'Here'   'are'   'some'   'symbols'
于 2011-12-29T19:31:49.740 回答