how find occorrences of words in a cell array
조회 수: 3 (최근 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!