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 に答える