Matlab compiler usage

Prerequisites

UNIX/LINUX

You will need on your system at least :

  • MATLAB
  • the MATLAB Compiler Toolbox of the same version than the MATLAB one (=v4.10 if MATLAB is v4.10)
  • a compatible version of gcc (>=4.0.0 for a MATLAB Compiler v4.10)

Other systems

We do not need to run it on other systems, and so we did not test it.

Building an executable

Here is describe how to build an stand-alone executable from MATLAB sources using the MATLAB Compiler toolbox.

Synopsis

To build the application, just use the MATLAB compiler command

mcc -mv <app>.m

Notes :

  • For an application composed of multiple sources files, run the “mcc” command with the ONLY the main script as argument. The compiler will automatically detect and import all required dependencies.
  • For running your build, you will need to have the same version of the mcc Compiler and of the MCR Runtime

Example

  • Consider the following source :
    sinc_graphic.m
sz  = 10;
dsz = 0.25;
 
[ X, Y ] = meshgrid( -sz:dsz:sz, -sz:dsz:sz );
R = sqrt( X.^2 + Y.^2 );
Z = sin ( R ) ./ R;
 
% Display the result of the cardinal sine as a Surface Plot
surf ( X,Y,Z );
  • To build the application, use the command
mcc -mv sinc_graphic.m
  • This will produce the files :

    mccExcludedFiles.log
    sinc_graphic_main.c
    sinc_graphic_mcc_component_data.c
    sinc_graphic.prj

    readme.txt
    run_sinc_graphic.sh
    sinc_graphic


Only the 2 last ones are requested for the deployment. However, the readme.txt contains useful informations on how to run the application previously built.

Deployment

For running the build, you first need to install the “Matlab Compiler Runtime” environment (MCR). This application will be able to execute your build.

Matlab Compiler Runtime Installation

  • Locate the file “MCRInstaller.bin” which is situed in the MATLAB Compiler Toolbox directory.
  • Execute it. During the installation, it will be asked you to choose a target directory. In the following, we will call it ${MCR_ROOT}.

Application Installation

In the installation directory, just copy the files created during the build process :
readme.txt
run_<app>.sh
<app>

where :
<app> is the name of your main script, with the “.m” extension omitted

Example

On the Icare’s system, we proceed this way :

  • MATLAB has been installed in /usr/local/matlab, the toolbox directory is /usr/local/matlab/toolbox/ and the compiler one is in /usr/local/matlab/toolbox/compiler
  • So the Runtime Installer is situed in /usr/local/matlab/toolbox/compiler/deploy/glnx86/MCRInstaller.bin
  • It has been installed in ${HOME}/lib/MATLAB_Compiler_Runtime. This is our ${MCR_ROOT}.
  • The “sinc_graphic” application above has been deployed in ${HOME}/test by filling it with the files :

run_sinc_graphic.sh
sinc_graphic

Execution

Synopsis

Finally, to run the application,

  • Go in the installation directory,
  • Run the “.sh” file by typing
./run_<app>.sh ${MCR_ROOT}/<vXXX> <args>

where :

<app> is the name of your main script, with the “.m” extension omitted
<args> are the usual command line arguments
<vXXX> is the version of the compiler runtime to use

Example

  • Go in the directory ${HOME}/test
        cd ${HOME}/test
  • Launch the application
        ./run_sinc_graphic.sh ${MCR_ROOT}/v710/
  • You should obtain the widget

Surface Plot of a Cardinal Sine

More news

Highlights

AERIS/ICARE was migrated his good old FTP server to SFTP

For security reason, we are abandoning the FTP protocol in favor of SFTP on our distribution server. Depending of the way you are using this service, you can have to change the commands you are used to. Note that not all applications support the SFTP protocol, and some additional tools may need to be installed […]

01.03.2024

Tutorials

How to convert a matplotlib figure to a numpy array or a PIL image

Language/Format: Python
Description: For manipulating a figure build with matplotlib, it is sometimes requested to convert it in a format understandable by other python libraries. This can be useful for using scipy image filters or manually adding annotations for example.
This page details how to convert a matplotlib figure to a numpy 3D array of RGBA values, or directly to a PIL ( Python Imaging Library ) Image.
Author(s): Nicolas Pascal (ICARE)

10.02.2017

Tutorials

Reading a NetCDF file with Matlab and R

Language/Format: MATLAB
Description: This page gives pieces of code to read data in a NetCDF file
Author(s): Aminata NDIAYE (ICARE)

15.12.2015

Search