Import matlab workspace variable using matlab command line

Dear Brainstormers,

I have about 3000 .mat EEG files that I would like to import into brainstorm for further analysis. Is there a function I can use to import the workspace variables without having to manually import each file using the GUI?

I am trying to use the db_add function, but I keep getting an error for undefined function or variable.

Thanks,
Yagna Pathak

Hi Yagna,

Yes, you can use the db_add function, but you have to define carefully the inputs of the function. Particularly the data structure must be the structure used in the recordings .mat files in Brainstorm database. Here is an example script:

% Create subject
db_add_subject('SubjectXX');
% Create condition
iStudy = db_add_condition('SubjectXX', 'ConditionXX');
% Define data structure to import
nChannel = 302;
nTime    = 200;
DataMat = db_template('DataMat');
DataMat.F           = 1e-6 .* rand(nChannel, nTime);
DataMat.Time        = 1e-3 .* (0:(nTime-1));
DataMat.ChannelFlag = ones(nChannel, 1);
DataMat.DataType    = 'recordings';
DataMat.Comment     = 'What is shown in the tree';
DataMat.nAvg        = 1;
% Add it to the database
db_add(iStudy, DataMat);

Francois

Thanks. That worked!

Thanks! That did the trick.

What is the unit for nTime? milliseconds?
Would “samples” (as in channels x samples) be an appropriate input? Or, does this need to be converted to milliseconds or seconds using the sampling rate?

Thank you,

Jesse

Hi Jesse,

This script is confusing, it’s not clear what are samples and what is time. You can consider the modification below:

    nSamples    = 200;
    sfreq = 1000;
    DataMat = db_template('DataMat');
    DataMat.F           = 1e-6 .* rand(nChannel, nSamples);
    DataMat.Time        = (0:(nSamples-1)) ./ sfreq;
1 Like