batch processing (automating code processing)

조회 수: 5 (최근 30일)
maryam al labbad
maryam al labbad 2020년 11월 2일
댓글: maryam al labbad 2020년 11월 3일
Hi all,
I have a question about running a code on multiple datasets. I have seen many examples and methods, but unfortunetly, they did not work for me.
I have over 500 data sets, all have same structure of data but different numbers (arranged in sruct.array) so they are already in .mat form.
Those .mat files are stored on my computer as follow :mainfolder > 5 subfolder > N number of subsubfolder > 15 .mat files
Thus, for each subsusbfolder, there is 15 .mat files.
So, basically I want to process those .mat files by calling a function on all of those data sets automatically, but not really sure how to do so especially that I need a for loop to navigate my subfolders and subsubfolders to reach to the .mat files.
Any help would be appreciated.

채택된 답변

Mario Malic
Mario Malic 2020년 11월 2일
편집: Mario Malic 2020년 11월 2일
This will give you the structure containing all .mat files.
File_Struct = dir('**/*.mat');
Edit:
Use name and folder to get the full path to each .mat file.
File_Struct = dir(fullfile(myFolder, '**/*.mat'))
File_Path = cell(size(File_Struct,1), 1);
for ii = 1 : 1 : size (File_Struct,1)
File_Path {ii} = fullfile(File_Struct(ii).folder, File_Struct(ii).name);
fprintf(1, 'Now reading %s\n', File_Path {ii});
load(File_Path {ii}); %this is changed
data=myfunc1(data)% calling my function1
data=myfunc2(data)% calling my function2
Processed_Data(ii).Value = data; % structure
end
  댓글 수: 23
Mario Malic
Mario Malic 2020년 11월 3일
This time, I'll suggest you to read the documentation on the functions used in these two lines. I want to help, but if I'm going to answer every question you might have, it won't lead you further ahead.
So, read up on save and fullfile.
What value does fullfile return? What input arguments save function takes? Once you learn that, you'll be able to solve your problem. You were on the right track with the answer - does it deal with .name thing?
maryam al labbad
maryam al labbad 2020년 11월 3일
Great! thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by