How to load only a subset of .dat files into MATLAB?

4 views (last 30 days)
Hello,
I am currently trying to load only a subset of files (i.e. files 1 to 6) into MATLAB using the following piece of code
cd('D:\Documents\Goldsmiths\Experiments\Curiosity x agency\Data pilot')
files=dir(fullfile('D:\Documents\Goldsmiths\Experiments\Curiosity x agency\Data pilot','_*.dat'));
for k=1:numel(files)
load(files(k).name);
end
This code works, in that it loads all files that end in .dat in the specified directory. But I only want files 1:6. I tried doing it this way
cd('D:\Documents\Goldsmiths\Experiments\Curiosity x agency\Data pilot')
files=dir(fullfile('D:\Documents\Goldsmiths\Experiments\Curiosity x agency\Data pilot','001*.dat','002*.dat','003*.dat','004*.dat','005*.dat','006*.dat'));
for k=1:numel(files)
load(files(k).name);
end
but it didn't get me the expected results.
Could you please be so kind as to help me?

Answers (1)

Thorsten
Thorsten on 23 Jun 2016
for k=1:6
load(files(k).name);
end

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!