How do I import many excel files from one folder using a for loop?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Miguel Herrera
am 17 Aug. 2017
Beantwortet: Walter Roberson
am 17 Aug. 2017
Hi guys, very simple concept and I am new to matlab.
I want to know how to import data using xlsread via a for loop. For example:
myFolder = 'D:Miguel\Matlab Work\Raw Solar Data' %Path to the folder with the raw .xlsx files
I want to be able to save these files as variables in matlab (Data1, Data2, etc.).
I've tried a few things but nothing seems to work. Also, I want to be able to see what file is being saved.
filePattern = fullfile(myFolder, '*.xlsx');
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Saving %s\n', fullFileName);
Data{k} = xlsread(theFiles(k)); % code
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 17 Aug. 2017
That reading code looks pretty good. However, notice that you have
myFolder = 'D:Miguel\Matlab Work\Raw Solar Data' %Path to the folder with the raw .xlsx files
Remember that in MS Windows, if the first character after the drive letter colon is not a / or a \ then the path given does not generally refer to the root directory. The fix might be as simple as
myFolder = 'D:\Miguel\Matlab Work\Raw Solar Data' %Path to the folder with the raw .xlsx files
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!