Comparing 2 matrix with not the same dimension

Lets say I have these 2 following matrix (which are not the same dimension):
A=[2 1 4 3 5 6] B=[5 4 3 1]
My goal is to find the following logical array:
A2=[1 0 0 0 0 1]
where 1 is the logical condition when a value in A is missing in B (again it must check the whole array B because dimension are not the same).
Thank you so much in advance for your answer !
Regards,
Pierre

 채택된 답변

Star Strider
Star Strider 2017년 10월 28일
Use the ismember function and the logical negation ‘~’ operator:
A=[2 1 4 3 5 6];
B=[5 4 3 1];
A2 = ~ismember(A,B)
A2 =
1×6 logical array
1 0 0 0 0 1

댓글 수: 2

Works ! Thank you very much !
As always, my pleasure!

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2017년 10월 28일
all(A(:)' ~= B(:))

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2017년 10월 28일

댓글:

2017년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by