Вы можете просто сохранить все имена файлов в массиве ячеек и затем использовать цикл for:
allFilenames = {'C:\...\file1.csv','C:\...\file2.csv','C:\...\file3.csv'};
for ii=1:length(allFilenames)
filename=allFilenames{ii};
% Do something with variable "filename"
end
Другой вариант - сохранить их в структурном массиве (например, что обеспечивает функция dir
).
testDir = 'C:\Users\...\test';
template = '*.csv';
allFiles = dir(fullfile(testDir,template));
% This will produce an array of structures with the file name in field "name"
for ii=1:length(allFiles)
%Combine directory and file name into an absolute path to the file
filename=fullfile(testDir,allFiles(ii).name);
% Then do something with variable "filename"
end