Can some one help me with this?

4 Ansichten (letzte 30 Tage)
Tech VNGS
Tech VNGS am 10 Okt. 2017
Beantwortet: Walter Roberson am 10 Okt. 2017
I have an array of character
arr = 'cat;tom;jerry;dog;cat'
and i also have a list of word need to search
wordSearch = 'tom,cat,dog,maeo'
So I want to use my wordSearch to find the word match in my array. In this case, after search in my array base on wordSearch, that 3 word in my WordSearch which is 'tom, cat and dog' that actually found in the array. And only one that didn't match with the array. Can some one help me to set a counter to iterate the wordSearch compare with the arr, the output should be the number of the word that didn't found in the arr. Thank you!

Akzeptierte Antwort

KSSV
KSSV am 10 Okt. 2017
str = 'cat;tom;jerry;dog;cat' ;
numel(regexp(str,'cat')) % cat
numel(regexp(str,'dog')) % dog
numel(regexp(str,'tom')) % tom
  5 Kommentare
KSSV
KSSV am 10 Okt. 2017
str = 'cat;tom;jerry;dog;cat' ;
s = {'cat','dog','tom','meor'} ;
count = zeros(size(s)) ;
for i = 1:length(s)
count(i) = numel(regexp(str,s{i})) ;
fprintf('%s found for %d times\n',s{i},count(i)) ;
end
Tech VNGS
Tech VNGS am 10 Okt. 2017
Thank you very much. I got it now. Really appreciate about that.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 10 Okt. 2017
Hint: split the strings into parts, and setdiff()

Kategorien

Mehr zu Word games 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