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];
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\\');
[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
else
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;
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