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!

 채택된 답변

KSSV
KSSV 2017년 10월 10일

1 개 추천

str = 'cat;tom;jerry;dog;cat' ;
numel(regexp(str,'cat')) % cat
numel(regexp(str,'dog')) % dog
numel(regexp(str,'tom')) % tom

댓글 수: 5

Tech VNGS
Tech VNGS 2017년 10월 10일
Do you know the other way to do it with loop and if else?
KSSV
KSSV 2017년 10월 10일
loop for?
Tech VNGS
Tech VNGS 2017년 10월 10일
for the same problem above by using loop. One more question, for the one you commented above, is there anyway can you print out the one that not found in the array? for example I call numel(regexp(str,'meor')) which is not found in the array. then print out the word meor.
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 2017년 10월 10일
Thank you very much. I got it now. Really appreciate about that.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 10월 10일

0 개 추천

Hint: split the strings into parts, and setdiff()

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2017년 10월 10일

답변:

2017년 10월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by