How to use outerjoin for multiple files
1 次查看(过去 30 天)
显示 更早的评论
Could anyone please help me to solve this problem:
I have 5 files
file1.CSV (key1,var1)
file2.CSV (key1,var2)
file3.CSV (key1,var3)
file4.CSV (key1,var4)
file5.CSV (key1,var5)
How to use outerjoin for 5 files?
Thank you very much!
0 个评论
采纳的回答
Stephen23
2022-5-13
fnm = compose("file%d.csv",1:5);
tbl = readtable(fnm(1));
tbl.Properties.VariableNames = {'Key1','Var1'};
for k = 2:numel(fnm)
tmp = readtable(fnm(k));
tmp.Properties.VariableNames = {'Key1',sprintf('Var%d',k)};
tbl = outerjoin(tbl,tmp, 'MergeKeys',true);
end
display(tbl)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!