Compare each row of data with another vector data

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

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

Dear Matt, thanks, it works. I am going to accept this answer
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.
Hi Matt thanks, I have accepted this answer now.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 11월 22일

댓글:

2022년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by