Errors running .m script from command line

Hello,
I have been trying to get my feet wet with scripting for brainstorm. The first step in my pipeline (after importing raw data and manually editing registration) is to import events (of two types) from a pair of .mat files. I did this for one raw file, and saved the script. I then simply changed the filenames for the next (identical) dataset and tried using the script file:

% Input files
FileNamesA = {‘MTRS/@rawMTRS_SD_02_raw/data_0raw_MTRS_SD_02_raw.mat’};
% Start a new report
bst_report(‘Start’, FileNamesA);
sFiles = bst_process(‘CallProcess’, ‘process_evt_import’, FileNamesA, [], …
‘evtfile’, {’/Volumes/PHD/Pilot/MTRS/MEG/EMG/MTRS_SD_02_emg_left_hand.mat’, ‘ARRAY-SAMPLES’});
sFiles = bst_process(‘CallProcess’, ‘process_evt_import’, sFiles, [], …
‘evtfile’, {’/Volumes/PHD/Pilot/MTRS/MEG/EMG/MTRS_SD_02_emg_right_hand.mat’, ‘ARRAY-SAMPLES’});
% Save and display report
ReportFile = bst_report(‘Save’, sFiles);
bst_report(‘Open’, ReportFile);

I tried running this form command line ('matlab -nodesktop -nosplash -r “new_script, exit” '), and got errors:
Reference to non-existent field ‘Program’.
Error in bst_progress (line 59)
if ~isempty(GlobalData) && ~isempty(GlobalData.Program)
Error in bst_error (line 130)
bst_progress(‘stop’);
Error in bst_call (line 31)
bst_error();
Error in macro_methodcall (line 39)
bst_call(str2func(varargin{1}), varargin{2:end});
Error in bst_report (line 53)
macro_methodcall;
Error in script_import_events (line 8 )
bst_report(‘Start’, FileNamesA);

If I comment out the report generation, I still get errors:


** Error: Line 1848: Attempt to reference field of non-structure array.
**
** Call stack:
** >panel_process_select.m>GetProcess at 1848
** >bst_call.m at 26
** >macro_methodcall.m at 37
** >panel_process_select.m at 29
** >bst_process.m>CallProcess at 1051
** >bst_call.m at 26
** >macro_methodcall.m at 37
** >bst_process.m at 30
** >script_import_events.m at 9
**



** Error: Line 1053: bst_process>CallProcess (line 1053)
** Unknown process.
**
** Call stack:
** >bst_process.m>CallProcess at 1053
** >bst_call.m at 26
** >macro_methodcall.m at 37
** >bst_process.m at 30
** >script_import_events.m at 9
**


Not sure what is going on. Help!

Hello,

Those scripts need to have the Brainstorm database system running in the background.
You need either to run Brainstorm before running your script, or add “brainstorm nogui” at the beginning your script.

Cheers,
Francois

Aha, I did have brainstorm open, but the nogui line worked.
I think when I installed brainstorm I did not have Matlab, but I have installed it since. This might be related?

Is there a way to supply names for the events in the script, so that I don’t have to provide them in the pop-up windows?

Is there a way to supply names for the events in the script, so that I don't have to provide them in the pop-up windows?

For what purpose? Can you describe better what you are doing?

I am trying to set up a batch script to do a number of brainstorm tasks (import raw data, import events, epoch and average the data, etc). The data will be the same every time, so I want to be able to specify all the parameters, names, etc up front, so I can just hit run, and not need to watch it.

You can go this way:

  1. Create your full analysis pipeline for one file using the pipeline editor (process1 tab)
  2. Generate a Matlab script for it
  3. Edit script: change the files list to include all the files you want to process, and move everything between the two calls to bst_report into a big for loop