Land data from multiple subfolders into structure
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to create a structure from multiple data files for multiple participants. When I run the following code, an empty structure is created. None of the data files loads. I'm not getting any errors. Screenshot of the files in the path is below.
I am a relatively new user, so it may be something simple.

% Create a Directory
Fold = dir('path');
SubFolds = Fold([Fold.isdir]); % keep only the directories
% Loop each folder
% For loop: Read each signal file into a data structure, then save incase we want it later
for i = 1:length(SubFolds)
data.EDA = readtable(join([Fold,'/',SubFolds(i),'/EDA.csv'],''));
data.ECG = readtable(join([Fold,'/',SubFolds(i),'/ECG.csv'],''));
data.EEG = readtable(join([Fold,'/',SubFolds(i),'/EEG.csv'],''));
data.PPG = readtable(join([Fold,'/',SubFolds(i),'/PPG.csv'],''));
data.ACC = readtable(join([Fold,'/',SubFolds(i),'/ACC.csv'],''));
disp('Participant Sructure.');
name = ['SubFolds',num2str(i)];
save(fullfile(join([Fold,'/',SubFolds(i)],''),name),'data')
end
% Lists with all of the subject Numbers and File names
parts = ["P01","P02","P03","P04","P05","P06","P07","P08","P09","P10","P11","P12","P13","P14","P15","P16","P17"];
signals = ["EDA.csv",'PPG1.csv','PPG2.csv','ECG.csv','EEG.csv'];
2 comentarios
Stephen23
el 2 de Nov. de 2023
Editada: Stephen23
el 2 de Nov. de 2023
"When I run the following code, an empty structure is created"
Which structure? Do you mean that SUBFOLDS is empty? That would occur if no folders were found by DIR on the specified path. Which makes sense, because there are no folders in your screenshot named "path".
Instead of using "path", you need to use the an absolute/relative path to the main folder.
Respuesta aceptada
Taylor
el 2 de Nov. de 2023
You are not calling dir properly. The string input to dir should be an absolute or relative path name. Try changing the string to 'Import_Data'.
https://www.mathworks.com/help/matlab/ref/dir.html
4 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Search Path en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!