Land data from multiple subfolders into structure

조회 수: 8 (최근 30일)
Susan
Susan 2023년 11월 2일
댓글: Voss 2023년 11월 2일
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.
Susan
Susan 2023년 11월 2일
I got it! Thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

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
Susan
Susan 2023년 11월 2일
Oh my gosh!!! That's SO much easier!
Thank you!
Voss
Voss 2023년 11월 2일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by