User Reference:Matlab Tools: Difference between revisions
No edit summary |
No edit summary |
||
| Line 15: | Line 15: | ||
* remove everything BCI2000-related from the Matlab and system paths again | * remove everything BCI2000-related from the Matlab and system paths again | ||
Of course, before you can call <tt>bci2000path</tt>, Matlab needs to know where <tt>bci2000path</tt> itself is. This chicken-and-egg problem is typical of Matlab path-juggling. You could use the graphical PATHTOOL to add an absolute | Of course, before you can call <tt>bci2000path</tt>, Matlab needs to know where <tt>bci2000path</tt> itself is. This chicken-and-egg problem is typical of Matlab path-juggling. You could use the graphical PATHTOOL to add an absolute reference to the <tt>tools/matlab</tt> directory "permanently" to the Matlab path, but anyone who has made heavy use of Matlab for some time will know that this often leads to problems sooner or later. Personally, I write the following lines either in my <tt>startup.m</tt> file, or in some other handy function in the <tt>My Documents\MATLAB</tt> or <tt>$HOME/matlab</tt> directory: | ||
olddir = pwd; | olddir = pwd; | ||
Revision as of 23:58, 27 January 2012
In the tools/matlab directory of your BCI2000 distribution, there are several of Matlab m-files that are useful for offline analysis of recorded data-files, from the Matlab command-line or in your own custom scripts. (If you prefer clicking the mouse to writing lines of Matlab code, you will probably be happier with the Offline Analysis Matlab GUI or the—now non-Matlab-based— P300Classifier tool.)
Here we provide an overview of the main Matlab functions without going into the details of their calling syntax. As always, you can go to the Matlab prompt and type something like
>> help bci2000chain
to get documentation on a particular function.
BCI2000PATH
This is a bootstrapping utility. Before you do anything, Matlab needs to know where the tools are. This function allows you to:
- tell Matlab where your BCI2000 distribution is
- return the full absolute path to a sub-part of the BCI2000 distribution. For example, bci2000path('tools/matlab/bci2000path.m') would return the full path to this file itself (or at least, to where it should be).
- add subdirectories of the BCI2000 distribution to the Matlab path, for the duration of the current Matlab session
- add subdirectories of the BCI2000 distribution to the system shell's path, for the duration of the current Matlab session
- remove everything BCI2000-related from the Matlab and system paths again
Of course, before you can call bci2000path, Matlab needs to know where bci2000path itself is. This chicken-and-egg problem is typical of Matlab path-juggling. You could use the graphical PATHTOOL to add an absolute reference to the tools/matlab directory "permanently" to the Matlab path, but anyone who has made heavy use of Matlab for some time will know that this often leads to problems sooner or later. Personally, I write the following lines either in my startup.m file, or in some other handy function in the My Documents\MATLAB or $HOME/matlab directory:
olddir = pwd;
cd('C:\BCI2000') % The absolute path has to be hardcoded somewhere, and here it is. Watch out, in case this is (or becomes) incorrect
cd tools, cd matlab
bci2000path -AddToMatlabPath tools/matlab
bci2000path -AddToMatlabPath tools/mex
bci2000path -AddToSystemPath tools/cmdline % required so that BCI2000CHAIN can call the command-line tools
cd(olddir) % change directory back to where we were before
clear olddir
BCI2000CHAIN
The BCI2000 command-line tools allow the online processing performed by BCI2000 to be recreated exactly offline. This is possible because online BCI2000 modules consist of a chain of filters, each filter being implemented in a self-contained source file. We can therefore take the individual filter implementations and build them singly, as separate executables that can be called from the system command-line. Recreating a preprocessing chain offline is then a question of passing a stream of data through a chain of these filter tools, connected by an operating-system "pipe". The bci2000chain function uses the command-line tools, but hides the details and presents itself to you as a single Matlab function.
TODO
Link this page from