How to return row number of an element in a char matrix?
5 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Jan
on 27 Sep 2011
The array A is not a CHAR-matrix, but a "cell string".
A = {'aa';'ab';'ac';'ad'}
row = find(strcmp(A, 'ab'));
More Answers (1)
Wayne King
on 27 Sep 2011
Hi, one way:
A = {'aa';'ab';'ac';'ad'};
index = find(ismember(A,'ab')==1)
2 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!