How to return row number of an element in a char matrix?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!