Combine excel files into one

104 ビュー (過去 30 日間)
Ancalagon8
Ancalagon8 2022 年 10 月 19 日
コメント済み: Mathieu NOE 2024 年 4 月 17 日 16:05
I want to run the code below, inside every folder i have an excel file (data.xls) and i want to compare 10 excel files into 1. Can anyone help me?
path = 'D:';
S = dir(fullfile(path, '*', 'data.xls'))
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
data = readtable(F);
d = datetime(strcat(table2array((data(:,1))), {' '}, table2array((data(:,2 )))));
acceleration = table2array((data(:,3 )));
xlswrite('file.xls', data)
end
  1 件のコメント
Mathieu NOE
Mathieu NOE 2022 年 10 月 19 日
hello
you have to explain what data you want to extract , combine and save.
for the time being your doing things in the for loop that are not even in the saved output excel file (you r'e saving what you simply loaded from the input file)
so you have to explain your logic and probably share some input files as well if we want to test the code
all the best

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 10 月 19 日
編集済み: Mathieu NOE 2022 年 11 月 9 日
so I relicated the same folder tree and file name (same in every folder)
this is a slightly modified code , try it :
path = 'D:\2019';
S = dir(fullfile(path, '*', 'data.xls'))
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
data = readtable(F);
d = strcat(table2array((data(:,1))), {' '}, table2array((data(:,2 ))));
out = [d data(:,3)]; % date / time / acceleration
out = renamevars(out,'Var1','Date & Time');
writetable(out,'file.xls',"Sheet",k)
end
  67 件のコメント
Ancalagon8
Ancalagon8 2024 年 4 月 17 日 15:53
@Mathieu NOE thank you!!
Mathieu NOE
Mathieu NOE 2024 年 4 月 17 日 16:05
as always, my pleasure !!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by