naxchange
naxchange

Reputation: 913

Matlab: reading all of the files in the directory

I am trying to read all of the files in a directory with a given file name format. Their names are exp01.v2, exp02.v2 and so on. The set of files is stored in a folder in the current directory. My code, which is not working, looks something like this:

fileName = 'folderInCurrentDirectory/exp*.v2';
files = dir(fullfile(pwd,fileName));
for file = files
    someHandle = fopen(file.name)
    % do something
end

Any suggestions?

Upvotes: 2

Views: 1973

Answers (1)

Min Lin
Min Lin

Reputation: 3197

The first two lines are correct.

Then do:

for i = 1:size(files,1)
    someHandle = fopen(files(i,1).name)
    % do something
end

Upvotes: 2

Related Questions