Applying a single function to many files in one folder.

Hello,
I am trying to apply a function to many files in a single folder. I assume I need to use a loop to go through the folder and process the files, but Im not certain which command recalls said folder. Once the data has been moved through, I want the refined data to be stored into a separate folder (we'll call this Folder B). I then want to run a function which goes through Folder B and applies commands such as mean/standard deviation of the data.

댓글 수: 3

Note, that "apply a function to many files" is not clear. Are the files M-files, test files, data stored in MAT or Excel-Files?
Apologies-They are csv files.
Pick a suitable function for your file format (e.g. REDATABLE or READMATRIX) and follow the examples in the documentation:

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 9월 2일
FolderIn = 'D:\Your\Folder';
FolderOut = 'D:\Your\B'
FileList = dir(fullfile(Folder, '*.mat');
for iFile = 1:numel(FileList)
File = fullfile(Folder, FileList(iFile).name);
Data = load(File);
% Now do what you want with the data
NewData = Data;
save(fullfile(FolderOut, FileList(iFile).name), 'NewData', '-struct');
end

카테고리

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

제품

질문:

2021년 9월 2일

댓글:

2021년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by