필터 지우기
필터 지우기

check string in array

조회 수: 197 (최근 30일)
Amir Hamzah UTeM
Amir Hamzah UTeM 2012년 6월 6일
i have this array
d ={'A' 'B'
'hello' 'hi'
'enter' 'exit'
'me' 'you'
'love' 'hurt'
'what' 'how'};
if i enter,str1 = 'hello me what';
i want that answer =1 since str1 contain value in d(:,1)
else will return as 0 . can someone tell me how to do that?

답변 (1개)

Thomas
Thomas 2012년 6월 6일
is something like this what you want
d ={'A' 'B'
'hello' 'hi'
'enter' 'exit'
'me' 'you'
'love' 'hurt'
'what' 'how'};
% str1={'hello' 'me' 'what'};
%Edit
str1='hello me what';
str1=regexp(str1,' ','split');
check=ismember(str1,d); %use d(:,1) to check only first column
if sum(check)==3
output=1
else
output=0
end
  댓글 수: 2
Amir Hamzah UTeM
Amir Hamzah UTeM 2012년 6월 6일
how about if str1='hello me what'
still can use it?
how to separate the word?
Thomas
Thomas 2012년 6월 6일
in that case use
str1='hello me what';
str1=regexp(str1,' ','split');

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

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by