Having Matlab run different files sequentially.

3 views (last 30 days)
Ok, so I have a folder full of excel files, each file with a different name. I also wrote a program to analyze the data. I thought about manually changing the xls read command to suite the name of the file, but then I was thinking "there has to be a way for matlab to run through these files sequentially." Anyone know how to do that? Keep in mind that all of the files have different names. I would be willing to go back and change the file names to suite matlab a little better, but the gists of the thing is that I want matlab to load the file, run the program, save the data the program is supposed to extract and then move on to the next file in the sequence. Also keep in mind that I need to save the extracted data from every file. I don't want the data to go away every time a new file runs. Thanks in advance.

Accepted Answer

Oleg Komarov
Oleg Komarov on 1 Aug 2011
Reference: faq 4.12
% Retrieve files in directory by extension
s = dir('C:\Users\Oleg\Desktop\*.xlsx');
% Loop over the files
names = {s.name};
for n = 1:numel(names)
xlsread(['C:\Users\Oleg\Desktop\' names{n}])
% do stuff
end

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!