How to apply function to certain files in directory
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a directory full of different files. The function I have will fopen and fread the content and process it to create other files. My function takes in parameter (parameter being the title of the file), but I would like to make the function run through the directory and read only the .raw files in that folder. Any help?
댓글 수: 0
채택된 답변
Pawel Jastrzebski
2018년 7월 16일
Just get the function to work on the selected files in the folder to begin with:
i.e.
fileNames = dir('*.raw'); % structure
fileNames = {fileNames.name}; % actual names extracted to cell array
댓글 수: 1
Moulvi Faizan Ahmed
2019년 12월 11일
But for the above method to be applicable the folder has to be in the current directory.
I need help on how to do the above requested task when the folder is not in the current directory and i dont want to change the directory.
추가 답변 (1개)
Stephen23
2019년 12월 11일
편집: Stephen23
2019년 12월 11일
D = 'relative/absolute path to the directory where the files are saved';
S = dir(fullfile(D,'*.raw'));
for k = 1:numel(S)
F = fullfile(D,S(k).name);
yourFunction(F)
end
댓글 수: 1
Moulvi Faizan Ahmed
2019년 12월 11일
편집: Moulvi Faizan Ahmed
2019년 12월 11일
Worked like charm, thank you
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!