필터 지우기
필터 지우기

how can we apply logical or operation on character strings

조회 수: 22 (최근 30일)
Ayushi Saxena
Ayushi Saxena 2015년 12월 29일
답변: Azzi Abdelmalek 2015년 12월 29일
Hi... i have a group of string that contain words say cat, dog, sparrow . now i need to apply logical operation on these words like if i find cat, dog or both in a text file that contains these words then it should display its an animal & if i find sparrow then display should be bird.

답변 (3개)

Image Analyst
Image Analyst 2015년 12월 29일
Try strcmp() or strcmpi() to compare a variable to a string constant. Or, if you're comparing against a list of words, use ismember().
if strcmpi(yourAnimal, 'sparrow')
message = sprintf('Your animal is a bird.');
uiwait(helpdlg(message));
end

Matt J
Matt J 2015년 12월 29일
See STRFIND and friends.

Azzi Abdelmalek
Azzi Abdelmalek 2015년 12월 29일
Your_list={'cat' 'dog' 'horse' 'sparrow' 'swallow' 'dove'}
You can associate to each element a number that indicate if it's an animal or a bird
type=[1 1 1 2 2 2]
message={ 'it''s an animal' 'it''s a bird' }
For example, if
a='cat'
Try to find the answer, you can use ismember function

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by