Import trial from matlab workspace

Hi guys, I'm writing for a brief suggestion. Which is the matlab function that I should use which is equivalet to right click on my epoch and select 'import from matlab'?
Basically what I do is to extract each epoch, load it into my matlab work space. Let's image that my trial structure is named Rand in my matlab workspace, I take the Rand.F field, I randomize the data phase with phaseran matlab function, and I replace the old F field with this shuffled data. No problem to do it by script until the last step. Now, I want to reimport this new structure into my trial. I have a lot of trial so I can't do it manually by right click on each epoch and select 'Import from matlab'. I want to do it by script, how could I do?
Thanks

1 Like

In general, to find the callback associated with a menu or a button which has a label or a tooltip, you can search the string (eg. "Import from Matlab") with the tool "Find files" in Matlab (CTRL+SHIFT+F / include subfolders).
In your particular example, this is not very useful: it would take you to function node_import.m, which relies on the actual node objects in the database explorer, which you don't have access to from your scripts.

The simplest by far is to directly load/save the Matlab structures in the file.
To load one of your imported trials, use in_bst_data (accepts relative file names in input).
To save a structure back to the hard drive, use bst_save (you need to provide an absolute file name).
To get the absolute path from a relative filename, use file_fullpath.

Examples in the tutorial Scripting:
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Example:_Creating_a_new_file
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Example:_Editing_events
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Reference:_File_manipulation

Thanks!