Static Public Member Functions | List of all members
mirtk::Matlab Class Reference

#include <Matlab.h>

Collaboration diagram for mirtk::Matlab:
Collaboration graph

Static Public Member Functions

static void Initialize ()
 
static void InitializeApplication (const char **options, int count)
 
static MatlabInstance ()
 Get static singleton object.
 

Detailed Description

Interface to MATLAB Compiler Runtime (MCR)

The static Matlab::Initialize or Matlab::InitializeApplication functions should be called before any code that either makes use of the MCR C++ functions or code generated by the MATLAB Compiler, respectively. Only the first invocation of these functions will execute the MCR initialization code. This is to ensure that the MCR was initialized. Usually this initialization should take place at the begin of the main function already, after the parsing of the command-line options.

Code that makes use of the MATLAB C++ types and functions should include the MCR proxy header file instead of the C++ header files shipped with MATLAB itself. This guarantees that users only need an installation of the free MCR to execute the code. Note that mclmcrrt.h is included by mirtkMatlab.h and that it is recommended to include mirtkMatlab.h instead.

#include "mirtk/Matlab.h"
int main(int argc, char *argv[]) {
// Either load MCR libraries and environment only
// or initialize MCR completely
// [...] Use MATLAB types and functions
return 0;
}

Definition at line 71 of file Matlab.h.

Member Function Documentation

§ Initialize()

static void mirtk::Matlab::Initialize ( )
static

Load MATLAT Compiler Runtime libraries and set environment

Loads three main libraries (libmex, libmat, libmclmcr) and sets runtime environment for running MATLAB functions.

Use InitializeApplication to initialize a standalone MCR application, which will also call mclmcrInitialize. This function may be used if mclInitializeApplication is not required, e.g., when only using some of MATLAB's C++ types and functions such as to read/write a MAT file. If code generated from .m files using the MATLAB Compiler is called, use InitializeApplication instead. If the MCR application uses a mclRunMain function, however, call Initialize first in the main function and then InitializeApplication in the mclRunMain function.

This static function can be called at any time by the main thread before the execution of any MATLAB Compiler generated code. It will only initialize the MCR upon the first invocation.

See also
mclmrcInitialize
http://uk.mathworks.com/matlabcentral/newsreader/view_thread/240279

§ InitializeApplication()

static void mirtk::Matlab::InitializeApplication ( const char **  options,
int  count 
)
static

Initialize MATLAB Compiler Runtime

This function must be called before any of the code generated from .m files using the MATLAB Compiler is executed. It calls the MCR function mclInitializeApplication which implicitly loads the MCR libraries, and throws an error if this function failed.

The MCR application is terminated automatically by the destructor of the static singleton object, i.e., mclTerminateApplication must not be called explicitly by the user.

This static function can be called at any time by the main thread before the execution of any MATLAB Compiler generated code. It will only initialize the MCR upon the first invocation.

See also
mclmrcInitialize
mclInitializeApplication
http://uk.mathworks.com/matlabcentral/newsreader/view_thread/240279

The documentation for this class was generated from the following file: