Checking whether one row of an array is equal to the rows in a separate array

40 ビュー (過去 30 日間)
Hans123
Hans123 2019 年 7 月 17 日
コメント済み: Star Strider 2019 年 7 月 17 日
I trying to compare one row of an Array A with all the rows in another array B of the same size, the logical answer will be used in an if condition
The line I have below is what I am using. Currently the arrays are small enough for me to observe there are rows on both arrays that are equal, but the counter is not updating (the counter is my way of keeping track of equal rows).
for k=1:10
if isequal(A(k,1:3),B(:,1:3))
counter=counter+1
...
else
....
end
end
I hope I was articulate enough describe my question, please let me know whether the isequal is the right conditional statement to use

採用された回答

Star Strider
Star Strider 2019 年 7 月 17 日
I would be tempted to use the ismember function with the 'rows' option (or ismembertol with the 'ByRows' option).
  2 件のコメント
Hans123
Hans123 2019 年 7 月 17 日
works perfectly, thanks as always Star Strider. :)
Star Strider
Star Strider 2019 年 7 月 17 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by