Find the rows that have common elements for 4 arrays
Show older comments
Dear all, I have 4 files and created 4 arrays, I wanted to make a new array that includes the rows that their last column elements have same values. I used ismember commadn for 2 arrays but not sucessful for 4 files. Please find the files attached and my code as the following:
in1 = readtable ('in1_dmp.txt');
in2 = readtable ('in2_dmp.txt');
out1 = readtable ('out1_dmp.txt');
out2 = readtable ('out2_dmp.txt');
maxCas=5000;
in1 = table2array (in1);
casNum_m = in1(:,9);
btchNum_m = in1(:,10);
for i = 1 : length(btchNum_m)
eventNUm=(casNum_m+maxCas.*(btchNum_m-1));
end
%Delete column
in1(:,9:11) = [];
%Add new column
in1 = [in1 eventNUm];
in2 = table2array (in2);
casNum_m = in2(:,9);
btchNum_m = in2(:,10);
for i = 1 : length(btchNum_m)
eventNUm=(casNum_m+maxCas.*(btchNum_m-1));
end
%Delete column
in2(:,9:11) = [];
%Add new column
in2 = [in2 eventNUm];
out1 = table2array(out1);
casNum_n = out1(:,9);
btchNum_n = out1(:,10);
for i = 1 : length(btchNum_n)
eventNUm=(casNum_n+maxCas.*(btchNum_n-1));
end
%Delete column
out1(:,9:11) = [];
%Add new column
out1 = [out1 eventNUm];
out2 = table2array(out2);
casNum_n = out2(:,9);
btchNum_n = out2(:,10);
for i = 1 : length(btchNum_n)
eventNUm=(casNum_n+maxCas.*(btchNum_n-1));
end
%Delete column
out2(:,9:11) = [];
%Add new column
out2 = [out2 eventNUm];
idx1 = ismember(in1(:,9),in2(:,9));
in1_com = in1(idx1,:);
%
% idx2 = ismember(in2(:,9),in1(:,9));
% in2_com = in2(idx2,:);
%
% idx3 = ismember(out1(:,9),out2(:,9));
% out1_com = out1(idx3,:);
%
% idx4 = ismember(out2(:,9),out1(:,9));
% out2_com= out2(idx4,:);
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion 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!