Compare each row of data with another vector data

2 次查看(过去 30 天)
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 个)

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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by