Compare to rows and delete matching rows

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 Kommentare

Rik
Rik am 10 Mär. 2019
Your screenshots look like your data is still in Excel and not yet in Matlab arrays. Once they are in Matlab you should be able to use ismember. What have you tried so far?
Curious Mind
Curious Mind am 10 Mär. 2019
I transfered them to matlab but the ismember function is not helping. Maybe its my code
Image Analyst
Image Analyst am 11 Mär. 2019
Make it easy for people to help you by attaching your Excel workbook.
Curious Mind
Curious Mind am 11 Mär. 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!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

dpb
dpb am 10 Mär. 2019

0 Stimmen

[~,ib]=ismember(A,B(:,1));
B(ib,:)=[];

3 Kommentare

Curious Mind
Curious Mind am 10 Mär. 2019
This is the error message I received in matlab
Subscript indices must either be real positive integers or logicals.
dpb
dpb am 11 Mär. 2019
Bearbeitet: dpb am 11 Mär. 2019
Show your work...
>> A
A =
11
14
>> B
B =
11.0000 0.0522 0.7477
14.0000 0.5712 0.3202
12.0000 0.4929 0.2217
>> [~,ib]=ismember(A,B(:,1))
ib =
1
2
>> B(ib,:)=[]
B =
12.0000 0.4929 0.2217
>>
Works to solve the described problem...
Curious Mind
Curious Mind am 11 Mär. 2019
It works!
Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 10 Mär. 2019

0 Stimmen

Try ismember() or ismembertol().

Kategorien

Mehr zu Large Files and Big Data finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 10 Mär. 2019

Kommentiert:

am 11 Mär. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by