How to find an element in a row, corresponding to an element (in same row number) in another matrix?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to find the location of an element (in terms of column number only) in a row (Let us assume this matrix to be A), corresponding to an element which exists in another matrix(Let us assume this matrix to be B).
Dimension of A=[1000X5]
Dimension of B=[1000X1]
MWE
A=[1,2,3,2,5;6,7,8,9,10;11,12,13,14,15];
B=[2;9;11];
(The answer is supposed to be [2;4;1])
Now I want to find the location (in terms of column number only) of 2, 9 and 11 (from matrix B) in row1,row2 and row3 (of matrix A)? Row1 (in A) contains two 2's therefore I want to choose the first location of 2 i.e. 2. Any pointers for this problem?
0 个评论
回答(2 个)
SuperNano
2013-5-12
You can use the find function. If you give it two variables as outputs it will return the corresponding column and row indices of all instances in the matrix where it finds the value you're after. Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!