how find occorrences of words in a cell array
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have two cell array uniqueWord e word (attached): I want to know, how many times the words in uniqueWord are presents in word, can you help me?
0 件のコメント
採用された回答
Andrei Bobrov
2017 年 7 月 17 日
編集済み: Andrei Bobrov
2017 年 7 月 17 日
[~,c] = ismember(word,uniqueWord);
out = [uniqueWord, num2cell(accumarray(c,1))];
0 件のコメント
その他の回答 (1 件)
Sebastian Castro
2017 年 7 月 17 日
You can use the strcmp (string compare) function to search for matches with a particular word. Then, you can use the nnz (number of non-zeros) function to count the number of hits.
For example:
>> nnz(strcmp(word,'sleep'))
ans =
10
You can then either loop through all the words you want to search for, or you can look into cellfun to apply the same code as above for all elements of the uniqueWord array. Up to you.
- Sebastian
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!