Characters linear search

2 vues (au cours des 30 derniers jours)
javeed miyandad
javeed miyandad le 28 Mar 2011
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

Réponse acceptée

Andrew Newell
Andrew Newell le 28 Mar 2011
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 commentaires
Matt Fig
Matt Fig le 28 Mar 2011
if isempty(I),disp('No match found.'),end
javeed miyandad
javeed miyandad le 28 Mar 2011
thank you very much sir

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by