Loop through multiple levels of subfolders to run .mat files
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Cassandra Martin
le 11 Fév 2022
Commenté : Cassandra Martin
le 11 Fév 2022
Hi, I'm new here and this is my first question (also very new to coding). I'll do my best to explain what I'm trying to do.
Here is my set up:
Participant Data > Subject (1-30) > trial 1 & trial 2 > apart & together > (7 total .mat files)
the names of the files are like: a_eo, t_eo, a_ec, t_ec, ..... so each subject has the same names of .mat files
I have a main code that can run the individual files, but to do 814 individually is ridiculous (wich I stared to do but realizd there has got to be a better way). I feel like this can be done with some nested loops, but I don't know how to loop through the folders since they contain letters and numbers in the folder names. I do have code that allows me to export the processed data to specific excel rows (for each subject), but I am also unsure of how to include this into the loops as I need the processed data not to be overwritten.
some help would be greately appreciated! Thank you!!
2 commentaires
Voss
le 11 Fév 2022
This thread may be useful to refer to: https://www.mathworks.com/matlabcentral/answers/124586-how-to-process-multiple-file-in-matlab
Other than that, I'm not sure I can help further without knowing more about your setup and exactly what you want to do, e.g., you have 7 .mat files per subject and 30 subjects for a total of 814 files?
Réponse acceptée
Stephen23
le 11 Fév 2022
Modifié(e) : Stephen23
le 11 Fév 2022
P = 'absolute/relative path to the main directory';
S = dir(fullfile(P,'**','*.mat'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
D = load(F);
... your code that processes the imported file data, accessing the fields of D
... for example: D.whateverFieldYOuNeed
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Variables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!