EEGlab Import events on loop - error

4 次查看(过去 30 天)
I want my code to load all .set files in a folder (['E:\PM_Frequency\EEG\2_correctTriggers\), then import the events from .csv files ('E:\\PM_Frequency\\EEG_log_files\\EEG_Log_Files_Renamed\\') into the loaded .set files and save them into another directory ('E:\\PM_Frequency\\EEG_Data_To_Epoch\\').
It works fine when using the GUI, so I've used the history function from matlab:
clc
clear
sub = [1:44];
run = [1:3];
% Loop between all subjects and runs
for i = sub;
for j = run;
if exist(['E:\PM_Frequency\EEG\2_correctTriggers\',sprintf('p%i_%i.set', i,j)]);
EEG = pop_loadset('filename',sprintf('p%i_%i.set', i,j),'filepath','E:\\PM_Frequency\\EEG\\2_correctTriggers\\');
new_file_name = [EEG.filename];
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
EEG = eeg_checkset( EEG );
EEG = pop_importevent( EEG, 'append','no','event','E:\\PM_Frequency\\EEG_log_files\\EEG_Log_Files_Renamed\\',new_file_name,'fields',{'number' 'latency' 'duration' 'channel' 'bvtime' 'bvmknum' 'type' 'code' 'urevent'},'skipline',1,'timeunit',1);
[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
EEG = eeg_checkset( EEG );
EEG = pop_saveset( EEG, 'filename',new_file_name,'filepath','E:\\PM_Frequency\\EEG_Data_To_Epoch\\');% or .filename
[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
else
%do nothing
end
end
end
But I've received the following error message after executing the code:
pop_loadset(): loading file E:\\PM_Frequency\EEG\2_correctTriggers\p10_1.set ...
Reading float file 'E:\\PM_Frequency\EEG\2_correctTriggers\p10_1.fdt'...
Undefined function or variable 'ALLEEG'.
Error in set_events_using_log_files (line 19)
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
If I delete this line:
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
I get the following error message:
Index exceeds matrix dimensions.
Error in pop_importevent (line 223)
if iscell(args{index+1}), if iscell(args{index+1}{1}) args{index+1} = args{index+1}{1}; end; end; % double nested
Error in set_events_using_log_files (line 20)
EEG = pop_importevent( EEG,
'append','no','event','E:\\PM_Frequency\\EEG_log_files\\EEG_Log_Files_Renamed\\',new_file_name,'fields',{'number'
'latency' 'duration' 'channel' 'bvtime' 'bvmknum' 'type' 'code' 'urevent'},'skipline',1,'timeunit',1);
I would really appreciate any help,
Cheers

回答(1 个)

Monika Tutaj
Monika Tutaj 2023-2-11
Hello there,
I figured out how to import events in a loop, however they're not in .csv format but in .tag format, but maybe this will help you anyway.
First of all before my loop im setting all paths, cd(yourpath), loading all set files from my cd files = dir('*.set');.
All steps below i'm doing in a for loop (for i=1:length(files))
After running desired operations (ie filtering ica etc) im saving my set to the savepath i've defined earlier, AND in the same folder i will have my .tag files corresponding to .set. :
EEG = pop_saveset( EEG, 'filename',['ica_' files(i).name], 'filepath', save2); % saving after ica
cd(save2) %im changing cd to the folder where i have my saved sets
tags = dir('*.tag'); %choosing all tag files
EEG = pop_loadset('filename',['ica_' files(i).name], 'filepath', save2); %loading same set ive saved
EEG2 = pop_importevent(EEG, 'event',tags(i).name, 'fields', {'type', 'latency','duration','tag_type','channel' },'skipline', 3 , 'timeunit',1,'align', NaN,'optimalign','off');
I dont know if you will find it helpful, but thats what works for me.
Regards, Monika :)

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

产品


版本

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by