How to compile/save the data extracted/read from multiple excel files from each iteration of loop into a single file???

1 回表示 (過去 30 日間)
Hi I am new to Matlab. I am extracting data from multiple excel files and I wish to save the data that I extracted from each excel file for each iteration without over-writting it after each iteration. Attached herewith the code that I have written:
xlFiles = dir('*.xlsx');
N = length(xlFiles);
for i = 1:N
thisFile = xlFiles(i).name;
T = readtable(thisFile,'Range','ax3:ba9', 'ReadVariableNames',false);
Tmat = table2array(T);
end
xlswrite('data.xlsx',Tmat);
Thank you and hope to receive any response from you all soon. Happy New Year.

採用された回答

KSSV
KSSV 2022 年 1 月 1 日
編集済み: KSSV 2022 年 1 月 1 日
xlFiles = dir('*.xlsx');
N = length(xlFiles);
Tmat = cell(N,1) ;
for i = 1:N
thisFile = xlFiles(i).name;
T = readtable(thisFile,'Range','ax3:ba9', 'ReadVariableNames',false);
Tmat{i} = table2array(T);
end
Tmat = cell2mat(Tmat) ; % assuming that each excel file have same dimensions of data
xlswrite('data.xlsx',Tmat);
  1 件のコメント
kahhoong kok
kahhoong kok 2022 年 1 月 1 日
編集済み: kahhoong kok 2022 年 1 月 1 日
Thank you KSSV so much. You have saved my day. The codes are working exactly as what I want. Stay safe.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by