How to repeat the same codes/work on different datasets in different subfolders
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/709992/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/709997/image.png)
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.
Antworten (2)
Dave B
am 15 Aug. 2021
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 Kommentare
TADA
am 15 Aug. 2021
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 Kommentare
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!