MATLAB Answers

Compare to rows and delete matching rows

조회 수: 26(최근 30일)
Curious Mind
Curious Mind 10 Mar 2019
댓글: Curious Mind 11 Mar 2019
Update: I have attached to mat files. I want to compare the rows in file A to that of file B. If a number in the first column of B matches with that of a number in the first column of A, then the entire row in A in which the number matches with that in B should be deleted. So example if you look at file B, the number 12 is in column 1, row 2 and it matches with column 1, row 4 in A. In this case I want a code that will delete the entire row 4 in A. I will now be left with 6by4 matrix. I am trying to compare the headers and use it as a quide to remove rows in A that I dont want. I have a very large data set and having a code that can do this will be very helpful.
Thanks!
  댓글 수: 4
Curious Mind
Curious Mind 11 Mar 2019
@Image Analyst
Thanks for the information. I have attached to mat files. I want to compare the rows in file A to that of file B. If a number in the first column of B matches with that of a number in the first column of A, then the entire row in A in which the number matches with that in B should be deleted. So example if you look at file B, the number 12 is in column 1, row 2 and it matches with column 1, row 4 in A. In this case I want a code that will delete the entire row 4 in A. I will now be left with 6by4 matrix.
Thanks!

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

채택된 답변

dpb
dpb 10 Mar 2019
[~,ib]=ismember(A,B(:,1));
B(ib,:)=[];
  댓글 수: 3
Curious Mind
Curious Mind 11 Mar 2019
It works!
Thank you!

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

추가 답변(1개)

Image Analyst
Image Analyst 10 Mar 2019
Try ismember() or ismembertol().

태그

Community Treasure Hunt

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

Start Hunting!

Translated by