Running MATLAB M-files

It's easy to run any MATLAB M-file from the ApplicationLinker PlugIn. For a script called "MyScript.m", just enter "matlab" for the programme to execute, and enter "/r MyScript", and the script will automatically run.

The tricky part with MATLAB is to pass parameters to your functions - specifically things like the trial folder and the trial filename - which you will need to know to decide which data to process ! Unfortunately, the MATLAB interface does not allow such variable parameters to be passed on the ApplicationLinker.

Instead, you can use an intermediate text file to hold the parameters. Initially, parameters are passed from the ApplicationLinker PlugIn to a DOS batch file, which creates this file with each parameter on a separate line. The DOS batch file then calls a MATLAB script which reads in the parameters from the file, and stores them as string variables. Once this has been done, other scripts and functions can be called as normal, using the parameters.

You can find examples of a DOS batch file and a parameter reading M-file in a zip file here. In this example, the DOS batch file "ParamFile.bat" generates a text file called "MatlabParams.txt" in the working directory, and then calls the M-file "ReadTextParams.m" which reads in the parameters. You need to edit ParamFile.bat according to the number of parameters you want to pass - currently it takes three. ReadTextParams.m will read as many parameters as there are in the file, but you will need to edit that to call the functions you want to call.