How to repeat the same codes/work on different datasets in different subfolders
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi. I have a set of codes that perform a type of work on one dataset.
I would like the same set of codes to be performed on other datasets.
Each dataset is contained in different subfolders. There are 8 subfolders in total. Each one is contained in a bigger folder.
The subfolders are labelled in the format of 50Hz_sine(x) and the bigger folder is labelled as PZT + Human Activity.
Any help please. Thanks.
답변 (2개)
Dave B
2021년 8월 15일
Here's the pattern I often use for this kind of problem. What you do inside the subfolders sort of depends on what your analysis is and what's in the subfolders, but hopefully the general pattern is helpful (?)
top_fp = "D:\Master\Raw Lab Data\PZT + Human Activity"
sub_fps = dir("50Hz_sine*."); % the *. is a way to limit to folders, but you likely can just use * assuming there aren't any files with the same prefix
% storing in a cell might be useful, particularly if the results of each
% folder's analysis is a different size/shape
results = cell(1, numel(sub_fps));
for i = 1:numel(sub_fps)
% no idea what a datset looks like, say it was a bunch of csv files...
fl = dir(fullfile(top_fp, sub_fps(i).name, "*.csv"));
results{i} = nan(numel(fl), 3);
for ii = 1:numel(fl)
data = readmatrix(fullfile(top_fp, sub_fps(i).name, fl(ii).name));
results{i}(ii,1) = mean(data);
results{i}(ii,2) = std(data);
results{i}(ii,3) = numel(data);
end
end
댓글 수: 0
TADA
2021년 8월 15일
make a script that inspects all subfolders of the folder your data resides in:
dataRootPath = fullfile('D:', 'Masters', 'Raw Lab Data', 'PZT + Human Activity');
% find out whatever is inside the data root path
folders = dir(dataRootPath);
% keep only folders
folders = folders([folders.isdir]);
% remove the pesky '.' and '..' folder links, thank you windows...
folders = folders(~ismember({folders.name}, {'.', '..'}));
for i = 1:numel(folders)
currFolder = folders(i);
currPath = fullfile(currFolder.folder, currFolder.name);
% call whatever function you made and send the current path
% matlabDoMyBidding(currPath);
end
댓글 수: 0
참고 항목
카테고리
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!