Importing Subjects with continuous EEG .mat data to BST: process_import_data_raw ERROR

BST Team,

I am having a frustratingly difficult time adding 61 subjects with continuous EEG in a .mat format to my protocol. I have attempted many different routes, and thought that I found success with code below as everything ran smoothly. However, when I click the "Link to raw file" for each subject, I receive an error stating that the file was not found. While looking in the individual subject directories, the file exists but is 5KB... Yet, there is a .bst that is the correct size of the file (i.e. 550,000 KB). Each iteration of the script generates "BST> File converted to binary .bst format: 'Filename.bst'", and clearly this has some impact on the nonexistence of the corresponding .mat file within the subject data folder.

Thoughts on what is happening?
Would moving the actual file into this folder with the corresponding name resolve the issue?

Any assistance is greatly appreciated.

CODE
% SubjectNames is a 1x61 cell with all 61 subjects names %
for sub = 1:length(SubjectNames)
SubjectName = char(SubjectNames{sub});

% Condition will be the 'Group' that each subject corresponds to based
% on previously existing indexing %
if ismember(sub, Participants.N2N3Cycle1SourceEEG.UpdatedIndex.IHwoNC)
   Condition = 'IHwoNC';
end
if ismember(sub, Participants.N2N3Cycle1SourceEEG.UpdatedIndex.MDDHYP)
   Condition = 'MDDHYP';
end
if ismember(sub, Participants.N2N3Cycle1SourceEEG.UpdatedIndex.HC)
   Condition = 'HC';
end

% FLT_OnlyGoodEpochs_ForBST is a location that was previously defined
% and houses the continuous, raw .mat files
RawFile = [FLT_OnlyGoodEpochs_ForBST_Loc SubjectName '_FLT_Cyc1N2N3_AvgRef_OnlyGoodEpochs.mat'];

% Exporting File to BST %
sFiles = [];
sFiles = bst_process('CallProcess', 'process_import_data_raw', sFiles, [], ...
    'subjectname', SubjectName, ...
    'condition', Condition, ...
    'datafile',     {RawFile, 'EEG-MAT'}, ...
    'channelreplace', 1, ...
    'channelalign', 1, ...
    'evtmode',      'value');

ReportFile = bst_report('Save', sFiles);

clear RawFile

end

ERROR
Warning: File not found:
F:\Hypersomnia_N2N3Cycle1_SourceLocalization\OnlyGoodEpochs\Cycle1_N2N3_ForBrainstorm_OnlyGoodEpochs\Brainstorm_MainDirectory\Hypersomnia_SourceEstimation_Cyc1N2N3\data\DP001@rawDP001_FLT_Cyc1N2N3_AvgRef_OnlyGoodEpochs\data_0raw_DP001_FLT_Cyc1N2N3_AvgRef_OnlyGoodEpochs.mat

In file_fullpath (line 68)
In tree_callbacks (line 2008)
In bst_call (line 26)
In panel_protocols>CreatePanel/protocolTreeClicked_Callback (line 139)
Error using in_bst_data (line 43)
Data file was not found:
DP001/@rawDP001_FLT_Cyc1N2N3_AvgRef_OnlyGoodEpochs/data_0raw_DP001_FLT_Cyc1N2N3_AvgRef_OnlyGoodEpochs.mat
Please reload this protocol (right-click > reload).

Error in import_raw_to_db (line 40)
DataMat = in_bst_data(DataFile);

Error in tree_callbacks>@(h,ev)import_raw_to_db(filenameRelative) (line 1148)
gui_component('MenuItem', jPopup, , 'Import in
database', IconLoader.ICON_EEG_NEW, ,
@(h,ev)import_raw_to_db(filenameRelative));

Hello,

If you are importing averages or epochs, use the process “Import MEG/EEG: Existing epochs”, and not “Create link to raw file”.

Whenever there is a .bst file, it is supposed to go in a pair with a .mat file. You should never have to manipulate these .bst files by yourself, this is internal storage.

Francois

Francois,

Thank you for the timely response. These are matrices in the format of channels x samples (256 x Variable Sample Duration). Each file is a single matlab matrix, and thus I thought this to be an appropriate route.

However, I am currently working on importing the matrix variables directly from the workspace instead… As you described here: Import matlab workspace variable using matlab command line

This may be the most efficient route for my project.

Thoughts?

All the best,

Jesse

You can use the process “Import MEG/EEG: Existing epochs” to import data from Matlab .mat files.
It might be easier, with less risks of manipulation errors.

Additional information on how to manipulate files in the “Scripting” tutorial:
http://neuroimage.usc.edu/brainstorm/Tutorials/Scripting

Excellent. Much appreciated… I was able to successfully import by files using the db_add route, but certainly appreciate your guidance.