How to match two matrices based on two keys?

조회 수: 1 (최근 30일)
Mohamed Nedal
Mohamed Nedal 2020년 1월 10일
답변: Hiro Yoshino 2020년 1월 10일
Hello everyone,
Kindly find the attached file. I would like to know how to match these matrices based on two keys rather than one key?
I tried this code and for only one key (time).
xCOL = {'DOY','UT','lat','long'};
yCOL = {'DOY','UT','pf_30Mev','pf_60Mev'};
for i = 1:length(X)
X = array2table(X,'VariableNames',xCOL);
Y = array2table(Y,'VariableNames',yCOL);
output = innerjoin(X,Y,'LeftKeys','UT','RightKeys','Hour');
writetable(output, 'Matched.xlsx', 'Sheet', i);
end
The 1st column represents the day of year (DOY) and the 2nd column represents the time in hours.
I want to find the rows at which both the day and time of X and Y are the same.
Can you please tell me how?

답변 (1개)

Hiro Yoshino
Hiro Yoshino 2020년 1월 10일
The script below worked for me where "DOY" and "UT" were used as keys:
load("matlab.mat");
xCOL = {'DOY','UT','lat','long'};
yCOL = {'DOY','UT','pf_30Mev','pf_60Mev'};
X = array2table(X,'VariableNames',xCOL);
Y = array2table(Y,'VariableNames',yCOL);
output = innerjoin(X, Y,'Keys',[1 2]);

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by