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

1 visualización (últimos 30 días)
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)

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 21 de Sept. de 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 comentarios
mohammad
mohammad el 21 de Sept. de 2011
Hi Jan,
yes this the fastest that Fangjun told

Iniciar sesión para comentar.

Más respuestas (2)

Harry MacDowel
Harry MacDowel el 21 de Sept. de 2011
find(char(CELL)=='a')
Does that help?
  4 comentarios
mohammad
mohammad el 21 de Sept. de 2011
now this error:
??? Error using ==> eq
Matrix dimensions must agree.

Iniciar sesión para comentar.


Grzegorz Knor
Grzegorz Knor el 21 de Sept. de 2011
See in documentation:
doc strfind
strfind(CELL,'a')
  5 comentarios
Jan
Jan el 21 de Sept. de 2011
I definitely prefer Grzegorz's solution in the comment above:
find(strcmp(C, 'a'))

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by