finding number of a column in a cell (column that contains a specified string)

3 vues (au cours des 30 derniers jours)
how could it be done for finding first which array of a cell is equal a specified string and in second, what is number of column that contains this string
for example:
CELL={'a','b','c','d','e','f',...}
finding 'a' in CELL?(which row and column)

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 21 Sep 2011
CELL={'a','b','c';'d','e','f'};
[Row,Col]=ind2sub(size(CELL),find(ismember(CELL,'e')))
or
[Row,Col]=ind2sub(size(CELL),find(strcmp(CELL,'e')))
  5 commentaires
Fangjun Jiang
Fangjun Jiang le 21 Sep 2011
@Grzegorz, Good catch!
mohammad
mohammad le 21 Sep 2011
Hi Jan,
yes this the fastest that Fangjun told

Connectez-vous pour commenter.

Plus de réponses (2)

Harry MacDowel
Harry MacDowel le 21 Sep 2011
find(char(CELL)=='a')
Does that help?
  4 commentaires
Harry MacDowel
Harry MacDowel le 21 Sep 2011
I corrected the answer up there.
mohammad
mohammad le 21 Sep 2011
now this error:
??? Error using ==> eq
Matrix dimensions must agree.

Connectez-vous pour commenter.


Grzegorz Knor
Grzegorz Knor le 21 Sep 2011
See in documentation:
doc strfind
strfind(CELL,'a')
  5 commentaires
Jan
Jan le 21 Sep 2011
I definitely prefer Grzegorz's solution in the comment above:
find(strcmp(C, 'a'))
mohammad
mohammad le 21 Sep 2011
Hi Jan
OK let me check

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by