Land data from multiple subfolders into structure

1 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2023-11-2
编辑:Stephen23 2023-11-2
"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.

请先登录,再进行评论。

采纳的回答

Taylor
Taylor 2023-11-2
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by