How to run calculation based on excel files in a folder path via for loop

1 ビュー (過去 30 日間)
Emily 2022 年 6 月 22 日
コメント済み: Walter Roberson 2022 年 6 月 22 日
I'm trying to create a GUI that will ask the user for a folder path and do some calculations based on it.
There's anywhere between 1-15 files per folder.
I'm stuck at printing the table output and having matlab ignore any temporary files that starts with ~$
filePattern = fullfile(myFolder, '*.xlsx');
theFiles = dir(filePattern);
for k=1: length(theFiles)
baseFileName= theFiles(k).name;
fullFileName=fullfile(myFolder, baseFileName);
data1{k} =xlsread(theFiles(k), 2,'F10:end10');
TotalTemp{k}= sum(data1{k});
data2{k} =xlsread(theFiles(k), 3,'A10:end10');
TotalCost{k}= mean(data2{k});
T=table(Day, TotalTemp, TotalCost)
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 6 月 22 日
data1{k} =readMatrix(theFiles(k),'Sheet', 'B', 'Range','F10:end10');
theFiles(k) is the struct with the directory entry. You should be passing in the file name, which you stored in fullFileName


回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by