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

35 vues (au cours des 30 derniers jours)
FRANCESCA MITI
FRANCESCA MITI le 5 Mai 2022
Commenté : JinYang le 1 Avr 2025
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 commentaires
FRANCESCA MITI
FRANCESCA MITI le 24 Juin 2022
Thank you!
Chris Winnard
Chris Winnard le 4 Déc 2023
@Alexander Craik this was a big help to me too, thanks. :)

Connectez-vous pour commenter.

Réponses (1)

Öznur
Öznur le 13 Mar 2025
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 commentaire
JinYang
JinYang le 1 Avr 2025
%%
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur EEG/MEG/ECoG dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by