Hi,
I have one Vector A and one Matrix B with the same amount of rows:
A = [1;
3;
5;
5;
4];
B = [2,3,4,5;
1,2,4,6;
2,4,1,2;
4,5,6,2;
1,2,3,4];
I would like to use ismembertol for each row of A and B, such as
for i = 1:size(A,1)
result(i,1) = ismembertol(A(i, 1), B(i, :));
end
Is there any smarter way to do this or is using a for - loop fine?
Thanks in advance!

4 件のコメント

madhan ravi
madhan ravi 2019 年 3 月 28 日
What's your desired result? , the one you posted returns zero.
Klemens Schumann
Klemens Schumann 2019 年 3 月 28 日
Mixed up the dimension of my loop, now it's what I want to have!
My result should be:
result = [0;
0;
0;
1;
1];
madhan ravi
madhan ravi 2019 年 3 月 28 日
編集済み: madhan ravi 2019 年 3 月 28 日
Why not
any(A==B,2) %?
[comment moved to answer section]
Klemens Schumann
Klemens Schumann 2019 年 3 月 28 日
Works perfectly, thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by