EEGLAB Import .vhdr (bva) files and save as .set in a loop

34 ビュー (過去 30 日間)
FRANCESCA MITI
FRANCESCA MITI 2022 年 5 月 5 日
コメント済み: JinYang 2025 年 4 月 1 日
Hello,
first of all, I'm a beginner in coding so please forgive my bad style. Some of the code may be just copied from the GUI.
I am trying to load EEG files in.vhdr (Brain Vision) format and save them as individual .set files using EEGLAB.
I'm also trying to use a loop.
This is my code now:
%%
allmyfiles = dir('*.vhdr');
allmyfilenames = string({allmyfiles.name})';
newsetnames = [ "name1.set" "name2.set" ];
for n = 1:size(allmyfilenames,1)
bvsetName = allmyfiles(n).name;
newsetname = newsetnames(n);
EEG = pop_loadbv('c:mypath1', bvsetName, [], [] );
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'gui','off');
EEG = eeg_checkset( EEG );
EEG = pop_saveset( EEG, 'filename',newsetname,'filepath','c:mypath2');
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
EEG = pop_delset( EEG, [1] );
STUDY = []; CURRENTSTUDY = 0; ALLEEG = []; EEG=[]; CURRENTSET=[];
end
%%
The newsetname variable is a string variable, but I keep getting this error and I can't solve it.
Error using pop_saveset (line 117)
error: argument 'filename' must be a string
Thank you very much to those who will try to help me.
  3 件のコメント
FRANCESCA MITI
FRANCESCA MITI 2022 年 6 月 24 日
Thank you!
Chris Winnard
Chris Winnard 2023 年 12 月 4 日
@Alexander Craik this was a big help to me too, thanks. :)

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

回答 (1 件)

Öznur
Öznur 2025 年 3 月 13 日
Hi,
I would like to upload EEG files in .vhdr (Brain Vision) format and save them as separate .set files using EEGLAB. I wanted to use your code above but I got the following error. Can you help me, please?
%%
allmyfiles = dir('C:\Users\IDU\Downloads\mbagul1.vhdr');
allmyfilenames = string({allmyfiles.name})';
newsetnames = [ "name1.set" "name2.set" ];
for n = 1:size(allmyfilenames,1)
bvsetName = allmyfiles(n).name;
newsetname = char(newsetnames(n));
EEG = pop_loadbv('c:mypath1', bvsetName, [], [] );
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'gui','off');
EEG = eeg_checkset( EEG );
EEG = pop_saveset( EEG, 'filename',newsetname,'filepath','c:mypath2');
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
EEG = pop_delset( EEG, [1] );
STUDY = []; CURRENTSTUDY = 0; ALLEEG = []; EEG=[]; CURRENTSET=[];
end
%%
And it returns:
Unrecognized function or variable 'pop_loadbv'.
Error in eed (line 8)
EEG = pop_loadbv('c:mypath1', bvsetName, [], [] );
Thank you, best regards..
  1 件のコメント
JinYang
JinYang 2025 年 4 月 1 日
%%
allmyfiles = dir('yourbrainvisionrawfilepath\*.vhdr'); %change the path to your brainvision file path
allmyfilenames = string({allmyfiles.name})';
for n = 1:size(allmyfilenames,1)
bvsetName = allmyfiles(n).name;
newsetname = char(allmyfilenames(n,1));
EEG = pop_loadbv('yourbrainvisionrawfilepath', bvsetName, [], []); %change the path to your brainvision file path
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'setname',newsetname,'gui','off'); %setname is set to be same as the vhdr raw file, delete('setname',newsetname,) if you don't need a setname
EEG = eeg_checkset( EEG );
EEG = pop_saveset( EEG,'filename',newsetname,'filepath','savepath'); %change the path to where you want to save the .set file
[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
clear EEG;
STUDY = []; CURRENTSTUDY = 0; ALLEEG = []; EEG=[]; CURRENTSET=[];
end
%%
Hi, not sure if you still need this, made some changes and it worked fine on my PC, also you may need to add eeglab to your matlab setpath and start eeglab, then just close it before running this program.

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

カテゴリ

Help Center および File ExchangeEEG/MEG/ECoG についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by