Compare each row of data with another vector data

4 ビュー (過去 30 日間)
Ganesh Naik
Ganesh Naik 2022 年 11 月 22 日
コメント済み: Ganesh Naik 2022 年 11 月 25 日
Hi all, I have two vectors each of two columns, different row length.
A B
I would like to check each row of A with each/all of B (they have different row lengths) and would like to assign '1' for each row A if its value falls in any of row B's values. I could able to achieve the answer in case of one column. Any help in this regard highly appreciated. I have include the data here.

採用された回答

Matt J
Matt J 2022 年 11 月 22 日
tmp=[discretize(A,[B(:,1);inf],'Inc','left'),...
discretize(A,[-inf;B(:,2)],'Inc','right')];
out=all(tmp==tmp(:,1),2);
  1 件のコメント
Ganesh Naik
Ganesh Naik 2022 年 11 月 22 日
Hi Matt, thanks for this version of the answer as well.

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

その他の回答 (1 件)

Matt J
Matt J 2022 年 11 月 22 日
out=any(A(:,1)>=B(:,1).' & A(:,2)<=B(:,2).',2);
  3 件のコメント
Matt J
Matt J 2022 年 11 月 22 日
編集済み: Matt J 2022 年 11 月 22 日
Looks like you accepted the other one by mistake. However, I think the answer below is in fact the most efficient.
Ganesh Naik
Ganesh Naik 2022 年 11 月 25 日
Hi Matt thanks, I have accepted this answer now.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by