Hoffman2:Compiling MATLAB: Difference between revisions

From Center for Cognitive Neuroscience
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:
We have two example MATLAB scripts:
We have two example MATLAB scripts:


'''/u/home/FMRI/apps/examples/mcc/subfunction.m'''
'''/u/home/FMRI/apps/examples/mcc/matlabScript.m'''


This function can take any number of arguments and the text it prints out is based on the type of variables it receives.
This function can take any number of arguments and the text it prints out is based on the type of variables it receives.
Line 32: Line 32:




'''/u/home/FMRI/apps/examples/mcc/matlabScript.m'''
'''/u/home/FMRI/apps/examples/mcc/subfunction.m'''


Makes use of the subfunction() function.
Makes use of the subfunction() function.
Line 50: Line 50:
  end
  end


 
To compile this use the command
mcc -m /u/home/FMRI/apps/examples/mcc/matlabScript.m -R -singleCompThread -I /u/home/FMRI/apps/examples/mcc/subfunction.m





Revision as of 01:42, 21 March 2012

Back to all things Hoffman2

Running the MATLAB GUI is not always desirable. If you already know that your code works and no visuals or user interaction are needed, then using the MATLAB GUI is unnecessary and adds extra work for the computer. Instead, it may be better to compile your MATLAB code into an executable that can be submitted as a job on Hoffman2.


Compiling

There is a handy tool mcc which can take a MATLAB .m file and compile it into an executable that can be run outside of MATLAB. It is expensive to buy, but luckily Hoffman2 has already done the purchasing for you.

We have two example MATLAB scripts:

/u/home/FMRI/apps/examples/mcc/matlabScript.m

This function can take any number of arguments and the text it prints out is based on the type of variables it receives.

function subfunction(varargin)

fprintf('This is a MATLAB function that takes input arguments.\n');

for i=1:length(varargin)
    if( ~isempty(varargin{i}) )
        switch class(varargin{i})
            case 'double'
                fprintf('Argument #%d\t -- %s -- is a double\n', i, varargin{i});
            case 'char'
                fprintf('Argument #%d\t -- %s -- is a char\n', i, varargin{i});
            otherwise
                fprintf('Argument #%d\t -- is an unknown\n', i);
        end
    end
end
end


/u/home/FMRI/apps/examples/mcc/subfunction.m

Makes use of the subfunction() function.

function matlabScript(varargin)

fprintf('Passing numbers to the subfunction...\n');
subfunction(1, 2, 3);

fprintf('Passing characters to the subfunction...\n');
subfunction('a', 'b', 'c');

fprintf('Passing whatever arguments you gave me on to the subfunction...\n');
for i=1:length(varargin)
    subfunction(varargin{i});
end

end

To compile this use the command

mcc -m /u/home/FMRI/apps/examples/mcc/matlabScript.m -R -singleCompThread -I /u/home/FMRI/apps/examples/mcc/subfunction.m



Submitting

Known Issues

Compiling EEGLAB has thus far failed on Hoffman2. Compiling SPM5 or SPM8 may fail similarly. If you figure out how to do this, let us know.


External Links