Loading files with different names in MatLab

I'm trying to read .vhdr files into MatLab in a loop function, but they all contain a different date in the filename. How can I get this to work? It's in the structure below where it starts with '01_' then has the subject number '####', then 'rest' and then the date of collection '02202021' then the .vhdr filetype.
File name structure: '01_####_rest_02202021.vhdr'
I have defined my subject numbers above in a variable called subject.
Such as:
subject = {'00001', '00002', '00003'}
EEG=poploadbv('C:/Users/M/Datasets',['01_',subject,'_Rest_','*.vhdr']);

回答 (1 件)

Jan
Jan 2021 年 4 月 2 日

0 投票

Do you want to load all files inside a folder?
Folder = 'C:/Users/M/Datasets';
FileList = dir(fullfile(Folder, '*.vhdr'));
Data = cell(1, numel(FileList));
Subject = cell(1, numel(FileList));
for iFile = 1:numel(FileList)
FileName = FileList(iFile).name;
File = fullfile(FileList(iFile).folder, FileName);
Data{iFile} = poploadbv(File);
tmp = splitstr(FileName, '_';)
Subject{iFile} = tmp{2};
end

5 件のコメント

Meredith Abrams
Meredith Abrams 2021 年 4 月 2 日
The files needed are actually contained within subdirectories by the subject number. So, inside Datasets is a folder for 00001 within that folder is the .vdhr that I need. Each file structure is the same, I just need the .vhdr file for each subject. The rest of the code should run per participant and then loop back around to restart for 00002.
Jan
Jan 2021 年 4 月 3 日
編集済み: Jan 2021 年 4 月 4 日
@Meredith Abrams: Can you use the code I've suggested to your needs?
Meredith Abrams
Meredith Abrams 2021 年 4 月 6 日
Hi there! Thank you so much! This code does not fit my needs as all of the data are stored in separate directories rather than a single directory. I may change the way they are stored and try this though.
Jan
Jan 2021 年 4 月 7 日
Or use:
FileList = dir(fullfile(Folder, '**', '*.vhdr'));
Image Analyst
Image Analyst 2021 年 4 月 8 日
I believe using two stars :
Folder = 'C:/Users/M/Datasets';
FileList = dir(fullfile(Folder, '**/*.vhdr'));
should work. Does it not?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2021 年 4 月 2 日

コメント済み:

2021 年 4 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by