Compare two matrix and delete the same rows

조회 수: 1 (최근 30일)
Patrick
Patrick 2014년 10월 27일
답변: Andrei Bobrov 2014년 10월 27일
Say I have A= [1 2 3, 4 5 6, 6 7 8] and B= [4 5 7, 1 2 3, 7 6 4, 6 7 8]. How can I delete the rows in B that are the same with A? The result desired is B=[4 5 7, 7 6 4]
Thanks!

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 10월 27일
편집: Azzi Abdelmalek 2014년 10월 27일
A= [1 2 3; 4 5 6; 6 7 8]
B= [4 5 7; 1 2 3; 7 6 4; 6 7 8]
B(ismember(B,A,'rows'),:)=[]

Andrei Bobrov
Andrei Bobrov 2014년 10월 27일
setdiff(B,A,'rows')

David Sanchez
David Sanchez 2014년 10월 27일
A= [1 2 3; 4 5 6; 6 7 8];
B= [4 5 7; 1 2 3; 7 6 4; 6 7 8];
Lia = ismember(B,A,'rows');
B_new = B(~Lia,:)
B_new =
4 5 7
7 6 4

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by