how to find index of nx2 matrix by comparing elements
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jos (10584)
2016-5-31
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!