Filter löschen
Filter löschen

how find occorrences of words in a cell array

3 Ansichten (letzte 30 Tage)
elisa ewin
elisa ewin am 17 Jul. 2017
Bearbeitet: Andrei Bobrov am 17 Jul. 2017
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?

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 17 Jul. 2017
Bearbeitet: Andrei Bobrov am 17 Jul. 2017
[~,c] = ismember(word,uniqueWord);
out = [uniqueWord, num2cell(accumarray(c,1))];

Weitere Antworten (1)

Sebastian Castro
Sebastian Castro am 17 Jul. 2017
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

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by