Loop Through Loading Files Error

1 view (last 30 days)
Greg B.
Greg B. on 10 Jun 2015
Hi there.
I have a question about how to load in data from multiple directories, but the files I need to load all have the same name. Here's what I have thus far:
smoothlist1 = dir('smooth*');
for i = 1:numel(smoothlist1) % loop through smooth directories
path2 = sprintf('%s%s/Curves',path1,smoothlist1(i).name);
cd(path2); % change directories into Curves directory, where results.xy file is located.
data = load('results.xy');
end
I loop through each directory in a list I call
'smoothlist1'. Within each 'smoothlist1 directory, I change directories into ~/smoothlist1/Curves/. Within this directory, there is a file called results.xy. I need to load each of the results.xy file from each ~smoothlist1/Curves directory, but i am unsure how to do that. What I have above just loads in the final results.xy file in the last smoothlist1/Curves/ directory.
So the question is, how do I loop through loading in that results.xy file from multiple directories? I have tried doing data(j) = results.xy, where I add a counter for j, but that did not work. I would like to load these results.xy files into separate filenames as well.
Thank you for your help.
G

Answers (0)

Categories

Find more on File Operations 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!