[scripting] Display as an image

Hello.

I am currently developing a script that produce a matrix that I want to be able to visualize in brainstorm.
Displaying the matrix as a timeserie works well :

but when I select Display as an image, I got the following error :

Error using str_remove_common (line 29)
Invalid call to str_remove_common()

Error in figure_image>UpdateFigurePlot (line 887)
tmpLabels = str_remove_common(Labels{1});

Error in figure_image (line 26)
eval(macro_method);

Error in view_image_reg (line 177)
figure_image('UpdateFigurePlot', hFig, 1);

Error in view_matrix (line 123)
[hFig, iDS, iFig] = view_image_reg(M, Labels, [1,3], {'Signals','Time (s)'}, MatFile, hFig, , 1,
'$freq');

Error in tree_callbacks>@(h,ev)view_matrix(filenameFull,'Image') (line 2042)
gui_component('MenuItem', jPopup, , 'Display as image', IconLoader.ICON_NOISECOV,
, @(h,ev)view_matrix(filenameFull, 'Image'));

The data are encoded in a matrixmat and looks like this on the hard-drive :

At the line of the error, Label{1} contains [ 1 2 3] whereas it should contains {'Grasping','rest','constant'}; ( woks well if I manually set Label{1} to {'Grasping','rest','constant'} )

The file has been saved using :

    Out_DataMat = db_template('matrixmat');
    Out_DataMat.Value           = X';
    Out_DataMat.Comment     = 'Design Matrix';
    Out_DataMat.Description = names; % Names of the regressors 
    Out_DataMat.ChannelFlag =  ones(n_regressor,1);   % List of good/bad channels (1=good, -1=bad)
    Out_DataMat.Time        =  DataMat.Time;
    Out_DataMat = bst_history('add', Out_DataMat, 'Design', FormatComment(sProcess));
    OutputFiles{2} = bst_process('GetNewFilename', fileparts(sInput.FileName), 'design_matrix');
    % Save on disk
    save(OutputFiles{2}, '-struct', 'Out_DataMat');
    % Register in database
    db_add_data(iStudy, OutputFiles{2}, Out_DataMat);

I am forgetting something ?
Thanks for your help

Hi,

The Description field wants an Nx1 cell array and you're giving it a 1xN cell array. You just need to tranpose it:

Out_DataMat.Description = names';

I hope this helps,
Martin

1 Like

Thx for your help. It works !