Initialize the MATLAB Runtime

When integrating compiled MATLAB® functions into a Python® application, your code must initialize the MATLAB Runtime:

  1. Optionally, provide a list of startup options to the MATLAB Runtime using the initialize_runtime() function.

  2. Start the MATLAB Runtime, and load a MATLAB Runtime instance using the initialize() function of each compiled package used in the application.

Provide MATLAB Runtime Startup Options

    Note:   On Mac OS X, you must pass the MATLAB Runtime options to the mwpython command when starting Python. Use -mlstartup followed by a comma-separated list of MATLAB Runtime options. MATLAB Runtime options passed to initialize_runtime() are ignored.

The MATLAB Runtime has two startup options that you can specify:

  • -nojvm — disable the Java® Virtual Machine, which is enabled by default. This can help improve the MATLAB Runtime performance.

  • -nodisplay — on Linux®, run the MATLAB Runtime without display functionality.

You specify these options before you initialize the compiled MATLAB functions. You do so by calling the initialize_runtime() method of a generated Python package with the MATLAB Runtime options. The list of MATLAB Runtime options is passed as a list of strings. For example, to start the MATLAB Runtime for the package addmatrix with no display and no Java Virtual Machine:

import addmatrix

addmatrix.initialize_runtime(['-nojvm', '-nodisplay'])

If your application uses multiple Python packages, you call initialize_runtime() from only one package. The first call sets the run-time options for the MATLAB Runtime session. Any subsequent calls are ignored.

Start MATLAB Runtime with Compiled MATLAB Functions

To evaluate a compiled MATLAB function, load it into the MATLAB Runtime. Do this by calling the initialize() method of the generated Python package. The initialize() method returns an object that can be used to evaluate the compiled MATLAB functions in the package. For example, to start the MATLAB Runtime and load the MATLAB functions in the addmatrix package, use:

import addmatrix

myAdder = addmatrix.initialize()

    Note:   If the initialize_runtime() function is not called prior to the initialize() function, the MATLAB Runtime is started with no startup options.

More About

Was this topic helpful?