Find the rows that have common elements for 4 arrays

1 view (last 30 days)
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,:);
  2 Comments
Hamid
Hamid on 12 Jul 2022
@Jan Thank you for the comment. The aim was to create a new column by multiplying two columns. At the end I have 4 variables which I want to know which rows has the same value in their last columns as attached.

Sign in to comment.

Accepted Answer

Jan
Jan on 12 Jul 2022
What about:
intesect(intersect(intersect(in1(:,9), in2(:,9)), out1(:,9)), out2(:,9))
  3 Comments
Hamid
Hamid on 13 Jul 2022
the rows that have the elements of these common elements.
common=intesect(intersect(intersect(in1(:,9), in2(:,9)), out1(:,9)), out2(:,9))
I used ismember to find them but faced with the following problem. Could you please take a look? Many thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!