Hoffman2:Compiling MATLAB: Difference between revisions

From Center for Cognitive Neuroscience
Jump to navigation Jump to search
(Created page with "Back to all things Hoffman2")
 
No edit summary
Line 1: Line 1:
[[Hoffman2|Back to all things Hoffman2]]
[[Hoffman2|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 <code>mcc</code> 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/subfunction.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/matlabScript.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
==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==
*[http://www.mathworks.com/support/solutions/en/data/1-18448/?solution=1-18448 How to pass variables to compiled MATLAB code]

Revision as of 01:35, 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/subfunction.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/matlabScript.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




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