Find the rows that have common elements for 4 arrays
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Jan
2022년 7월 12일
What is the purpose of this loop:
for i = 1 : length(btchNum_m)
eventNUm=(casNum_m+maxCas.*(btchNum_m-1));
end
The body does not depend on i, so running it repeatedly is a waste of time only. This occurs several times, which is even more confusing.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!