Writing the M-file
The first step is writing the MATLAB M-file that you want to share. For this example, write a simple application that
takes a filename and a String and writes the String out to a file with the given name. This application consists of the
following lines:
% write the variable whatToWrite to a file called filename in the current
directory
fid = fopen(filename,'w');
fprintf(fid,'#writing to a file\n\n');
fprintf(fid,whatToWrite);
fclose(fid);
Adapting the M-file
To call the M-file from the command line and pass it parameters, you must turn this script into a no-return function. To
do this, add a function definition line at the start of the M-file and save the file using the name of the function (for
example, writeToFile.m).
function writeToFile( filename, whatToWrite)
% write the parameter whatToWrite to a file called filename in the current
directory
fid = fopen(filename,'w');
fprintf(fid,'#writing to a file\n\n');
fprintf(fid,whatToWrite);
fclose(fid);
Compile the M-file
Within the MATLAB environment, call the MATLAB Compiler to convert this function into an application:
>> mcc -m writeToFile
Within the current working directory, this creates a number of files, including the following:
● writeToFile.exe (Windows) or
writeToFile (Linux, Mac OS X)
● writeToFile.ctf
Note: To use the MATLAB compiler on Mac OS X, you must have Xcode 2.2 installed; minimally, the Developer
Tools, gcc 4.0, gcc 3.3, Mac OS X SDK, and BSD SDK. These instructions were tested using Xcode 2.2.1.
Prepare the GenePattern Server
Install the MATLAB Component Runtime (MCR) on the GenePattern server, if you have not done so already. If the
GenePattern server has MATLAB installed, it also has the MCR installed.
Windows
To install the MCR:
1. Copy
<matlabroot>\toolbox\compiler\deploy\win32\MRCInstaller.exe to the
GenePattern server machine.
2. At the DOS prompt, or from Windows Explorer, run the following:
MCRInstaller.exe
Linux or Mac OS X
To install the MCR:
1. Within the MATLAB environment, create the MCRInstaller zip file:
>> buildmcr mcrdir
This creates a directory, mcrdir, beneath the current working directory and creates a file within that directory
called
MCRInstaller.zip.
14
Commenti su questo manuale