Land data from multiple subfolders into structure
조회 수: 8 (최근 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
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
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 Center 및 File Exchange에서 Search Path에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!