Error in running loop for importing .cnt data file for multiple files

6 views (last 30 days)
Hello,
I am attempting to run a simple loop through EEGlab and am able to run each line of code individually but I encounter an error in an attempt to run a loop that imports, runs localization command, and save. The first subject can correctly be called and saved, however, when moving on to the next subject my script is unable to do so due to the following three errors:
Thank you in advance!
eeglab: options file is ~/eeg_options.m
EEGLAB warning: there can be only one EEGLAB window, closing old one
Retrieving plugin versions from server...
Retreiving download statistics...
EEGLAB: adding "Fieldtrip-lite" to the path; subfolders (if any) might be missing from the path
EEGLAB: adding "ICLabel" v1.2.6 (see >> help eegplugin_iclabel)
EEGLAB: adding "clean_rawdata" v2.2 (see >> help eegplugin_clean_rawdata)
EEGLAB: adding "dipfit" v3.3 (see >> help eegplugin_dipfit) - new version 3.4 available
EEGLAB: adding "eeglab_plugin_aar-master" v? (see >> help eegplugin_aar)
EEGLAB: adding "firfilt" v2.4 (see >> help eegplugin_firfilt)
EEGLAB: adding "neuroscanio" v1.3 (see >> help eegplugin_neuroscanio)
You are using the latest version of EEGLAB.
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in loadcnt (line 111)
h.rev = fread(fid,12,'char');
Error in pop_loadcnt (line 130)
r = loadcnt( fullFileName, varargin{:});
here is a copy of my script:
homefolder = '/Volumes/Backup Plus/BMC_Data/YA_CNT_Files';
datafolder = '/Volumes/Backup Plus/BMC_Data/YA_CNT_Files';
cd(datafolder);
Files = dir('*.cnt');
cd(datafolder);
for i=1:length(Files)
[ALLEEG, EEG, ~, ALLCOM] = eeglab;
FileName = Files(i).name;
cd(datafolder);
thisfilename = FileName;
Ind1 = find(FileName == '.');
basefilename = thisfilename(1:Ind1-1);
EEG = pop_loadcnt('thisfilename', 'dataformat', 'auto', 'memmapfile', '');
EEG.setname= [basefilename '.set'];
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'setname',EEG.setname,'gui','off');
EEG = eeg_checkset( EEG );
[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG);
eeglab redraw
counter = 1;
EEG=pop_chanedit(EEG, 'lookup','/Users/lpez/Documents/MATLAB/eeglab2020_0/plugins/dipfit/standard_BESA/standard-10-5-cap385.elp');
EEG = eeg_checkset( EEG );
[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
EEG.setname = [basefilename '_1.set'];
pop_saveset( EEG, 'filename',EEG.setname,'filepath', datafolder);
clear EEG ALLEEG CURRENTSET
end
  1 Comment
Stephen23
Stephen23 on 20 Oct 2020
Edited: Stephen23 on 20 Oct 2020
Ugh, that cd is a bad omen... why not just provide an absolute/relative filename? That might resolve the issue.
Tip: use fileparts rather than messing about locating the period character to split the file-name and file-extension.

Sign in to comment.

Answers (1)

Joana
Joana on 4 Oct 2021
Hey Luke
Did you end up solving this problem.?
Currently i am facing the exact same error actually.

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!