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

조회 수: 3 (최근 30일)
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)

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 9월 21일
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
mohammad
mohammad 2011년 9월 21일
Hi Jan,
yes this the fastest that Fangjun told

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

추가 답변 (2개)

Harry MacDowel
Harry MacDowel 2011년 9월 21일
find(char(CELL)=='a')
Does that help?
  댓글 수: 4
mohammad
mohammad 2011년 9월 21일
now this error:
??? Error using ==> eq
Matrix dimensions must agree.

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


Grzegorz Knor
Grzegorz Knor 2011년 9월 21일
See in documentation:
doc strfind
strfind(CELL,'a')
  댓글 수: 5
Jan
Jan 2011년 9월 21일
I definitely prefer Grzegorz's solution in the comment above:
find(strcmp(C, 'a'))

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by