-2

I have multiple (264 to be precise) files with yearly precipitation, which are named 'precip1752.xlsx','precip1753.xlsx', ... 'precip2016.xlsx'. How can I load all these files at once with a for loop?

Thanks in advance!

Yoni Verhaegen
  • 111
  • 1
  • 11

1 Answers1

1

Let's say the files are in a directory with name dirName.

D = dir([dirName '*.xlsx']);
for di = 1:length(D)
    filePath = fullfile(dirName, D(di).name);
    % insert code here to process file named filePath using xlsread
end

Use the xlsread function to read the data into MATLAB.