Effacer les filtres
Effacer les filtres

Single line string find

1 vue (au cours des 30 derniers jours)
Chmical
Chmical le 27 Mar 2012
Is there a single line of code that would find a string in a cell array and output the column number? I have a large cell array of data with headers. I would like to be able to find a string but have the output give me the location (i.e. column number) of the found string. For example:
data = {'bab' 'bob' 'hey'}; test = 'bob'; Need the output to be 2 (bob is in the second column of the 1x3 data variable.
I can find bob and return [] [1] [] but not sure how to just get the column number without running a loop which takes time. I think there is probably a simple solution but I can't seem to visualize it.

Réponse acceptée

Matt Tearle
Matt Tearle le 27 Mar 2012
find(strcmp(test,data))
  1 commentaire
Chmical
Chmical le 27 Mar 2012
works like a dream. Thank you. Knew it should be something simple...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings 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