I have been given about one thousand .txt files that I need to open into Matlab and run a script on the extracted information from them. Currently I am changing the file path individually each time. Is there any way to set a loop to open each .txt file and perfom the script on them? This would save a lot of time. Currently the lines I am using to open the file goes like this: filename = 'C:\Users\.... formatSpec = '%f%*s%*s%*s%f%f%f%*s%*[^\n\r]'; fileID = fopen(filename,'r');

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 16일

1 개 추천

path='C:\Users\....'
d=dir(fullfile(path,'*.txt'))
file_names={d.name}
formatSpec = '%f%*s%*s%*s%f%f%f%*s%*[^\n\r]';
for k=1:numel(file_names)
f=fullfile(path,file_names{k})
fileID = fopen(filename,'r');
...
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by