Find elements of type (x,y) and indices for equality of columns x and y

1 次查看(过去 30 天)
Find number of elements of type (x,y) in two columns, where x is in one column and y in the other. Report the indices for elements of type (x,y) that are equal.
Example a = [1,1,2,1]; b = [1,2,2,1]; should give answer (2,2) for index 3.

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-11-4
编辑:Ameer Hamza 2020-11-4
In case of given 'a' and 'b', same value occur in three rows
a = [1,1,2,1]; b = [1,2,2,1];
idx = find(a==b)
Result
>> idx
idx =
1 3 4
  1 个评论
Torbjörn Olsson
Torbjörn Olsson 2020-11-4
Yes but this should work for an arbitrarly sized array. The indices should just be counted if they occur at least two times. Above a=x and b=y.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by