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

조회 수: 31 (최근 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
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 CenterFile Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by