필터 지우기
필터 지우기

How to return row number of an element in a char matrix?

조회 수: 4 (최근 30일)
Matthias
Matthias 2011년 9월 27일
Hello, I have a small question,
I have an example matrix below with char data in it;
A = {'aa';'ab';'ac';'ad'}
When I call a notation i.e. 'ab' previously on my code, I want matlab to return the row number of 'ab', so I could move to the next row. After I searched I've found "find" command, but it looks like "find" does not work for chars (I might be wrong). I typed the following inside a larger loop;
if Notation == 'ab'
[drow,dcol] = find(A,Notation);
Notation = A(drow+1,dcol);
else....
And returns the error: ??? Undefined function or method 'find' for input arguments of type 'cell'.
Can anyone spare me the correct function name for such a task?
Thanks in advance.
Matt
PS: It can be done one by one for such a small matrix, but because of this being an example I only create a 4x1 one, the real one is 260x1, so I need an actually working algorithm.

채택된 답변

Jan
Jan 2011년 9월 27일
The array A is not a CHAR-matrix, but a "cell string".
A = {'aa';'ab';'ac';'ad'}
row = find(strcmp(A, 'ab'));

추가 답변 (1개)

Wayne King
Wayne King 2011년 9월 27일
Hi, one way:
A = {'aa';'ab';'ac';'ad'};
index = find(ismember(A,'ab')==1)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by