How to match two matrices based on two keys?

1 次查看(过去 30 天)
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