check string in array

241 Ansichten (letzte 30 Tage)
Amir Hamzah UTeM
Amir Hamzah UTeM am 6 Jun. 2012
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?

Antworten (1)

Thomas
Thomas am 6 Jun. 2012
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 Kommentare
Amir Hamzah UTeM
Amir Hamzah UTeM am 6 Jun. 2012
how about if str1='hello me what'
still can use it?
how to separate the word?
Thomas
Thomas am 6 Jun. 2012
in that case use
str1='hello me what';
str1=regexp(str1,' ','split');

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by