how to find index of nx2 matrix by comparing elements
1 view (last 30 days)
Show older comments
Hi, giving a matrix of size nx2
A=[ 222,186;
222,187;
223,187]
giving 2 values i= 222 and j=187 i want to find the index the row that contain i on the first column and j on the seond wich is 2 here i want something like
i thought to do somthing like this
for k=1:size(A,1)
test=find(A(k,1)==i && A(k,2)==j)
if (test==1)
ind=k;
break;
end
end
i need only the first index like i did here but i want to avoid the loop.
Thanks
0 Comments
Accepted Answer
Jos (10584)
on 31 May 2016
A=[ 222,186;
222,187;
223,187]
i = 222
j = 187
% two alternatives
r1 = find(A(:,1)==i & A(:,2)==j))
[tf,r2] = ismember(A,[i j],'rows')
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices 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!