Characters linear search

sir i need to store characters like (man cat red blue) in 2X2 matrix and then i need to perform linear search , that is if i give man it must result man is first character please help in coding

 채택된 답변

Andrew Newell
Andrew Newell 2011년 3월 28일

0 개 추천

You can use cell arrays and string comparisons to do this:
>> A = {'man', 'cat'; 'red', 'blue'}'
A =
'man' 'red'
'cat' 'blue'
>> i = find(strcmp('man',A));
This gives the indices so that
A{i}
returns
ans =
man
( edited to respond to comment )

댓글 수: 4

javeed miyandad
javeed miyandad 2011년 3월 28일
thank you sir
i want to have single value
means it showing i=1, j=1
it must show just 1
ie for man- 1
cat -2
red-3 red -4
sir
javeed miyandad
javeed miyandad 2011년 3월 28일
thank you sir i got output
sir if i give like
i = find(strcmp('women',A));
since women is not there in A
i need to disply result like 'element is not found'
how can i do sir
Matt Fig
Matt Fig 2011년 3월 28일
if isempty(I),disp('No match found.'),end
javeed miyandad
javeed miyandad 2011년 3월 28일
thank you very much sir

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by