Comparing uneven sized matrix and delete rows which are not common

4 views (last 30 days)
Hi guys. I hope this quation finds you well.
For my project i need to compare two uneven matriz row by row. If the rows are not equal beteween column 2 and 5 in a line, delete the line which de index (i+1) is equal to the other matrix index (i). If a rows is deleted, the cycle must restart. Basically i want the column 2 and 5 be exactly equal on both matrices.
For now i have this:
close all;
clc;
D=load('Dir.txt');
L=load('Esq.txt');
D=sortrows(D,6);
L=sortrows(L,6);
for i=1:length(L);
if D(i , 5) ~= L(i , 5) | D(i , 2) ~= L(i , 2)
return
end
end
But i have to manually delete the rows. Is there an option to do this automatically?
I have to delete more than 70000 rows so if i do it manually i'll be done some time next year XD.
Thanks in advance.
P.S: The files are attached

Accepted Answer

Ameer Hamza
Ameer Hamza on 1 Dec 2020
Try this code
D = readmatrix('Dir.txt');
E = readmatrix('Esq.txt');
[tf, idx] = ismember(D(:, [2 5]), E(:, [2 5]), 'rows');
D_new = D(tf, :);
E_new = E(idx(idx~=0), :);
Are you looking for something like this?
  6 Comments
David Martins
David Martins on 1 Dec 2020
It works!!
Thank you so much for your time an effort to enlight me on this matter!
Wish you all the best.

Sign in to comment.

More Answers (0)

Categories

Find more on Elementary Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!