Main Content

matlab.engine.start_matlab

Start MATLAB Engine for Python

Description

eng = matlab.engine.start_matlab() starts a new MATLAB® process, and returns Python® variable eng, which is a MatlabEngine object for communicating with the MATLAB process.

If MATLAB cannot be started, the engine raises an EngineError exception.

example

eng = matlab.engine.start_matlab(option) uses startup options specified by option.

For example, call matlab.engine.start_matlab('-desktop') to start the MATLAB desktop from Python.

example

eng = matlab.engine.start_matlab(background) starts MATLAB asynchronously if background is True.

example

eng = matlab.engine.start_matlab(async) starts MATLAB asynchronously if async is True. Not recommended. Use the background argument instead. Do not use for Python Version 3.7 or later. For more information, see Version History.

eng = matlab.engine.start_matlab(___) can include any of the input arguments in previous syntaxes.

example

Examples

collapse all

Start an engine and a new MATLAB process from the Python command line.

import matlab.engine
eng = matlab.engine.start_matlab()

Start a different MATLAB process from each engine.

import matlab.engine
eng1 = matlab.engine.start_matlab()
eng2 = matlab.engine.start_matlab()

Start an engine with the MATLAB desktop.

import matlab.engine
eng = matlab.engine.start_matlab("-desktop")

You also can start the desktop after you start the engine.

import matlab.engine
eng = matlab.engine.start_matlab()
eng.desktop(nargout=0)

Note

You can call MATLAB functions from both the desktop and Python.

Start the engine with background=True. While MATLAB starts, you can enter commands at the Python command line.

import matlab.engine
future = matlab.engine.start_matlab(background=True)
eng = future.result()
eng.sqrt(4.)
2.0

Input Arguments

collapse all

Startup options for the MATLAB process, specified as a string. You can specify multiple startup options. The engine supports all MATLAB startup options, except for the options listed in Limitations. For a list of options, see the platform-specific command matlab (Windows), matlab (macOS), or matlab (Linux).

To start MATLAB with the desktop, use the '-desktop' option.

Example: matlab.engine.start_matlab('-desktop -r "format short"') starts the desktop from Python. The engine passes '-r "format short"' to MATLAB.

Start MATLAB synchronously or asynchronously, specified as a logical keyword argument. background is an alias for async.

Example: matlab.engine.start_matlab(background=True)

Start MATLAB synchronously or asynchronously, specified as a logical keyword argument. Not recommended. Use the background argument instead. For more information, see Version History.

Output Arguments

collapse all

Python variable for communicating with MATLAB, returned as a MatlabEngine object if async or background is set to False or a FutureResult object if async or background is set to True.

Each time you call matlab.engine.start_matlab, it starts a new MATLAB process.

Limitations

The engine does not support these MATLAB startup options:

  • -h

  • -help

  • -?

  • -n

  • -e

  • -softwareopengl

  • -logfile

For information on MATLAB startup options, see Commonly Used Startup Options.

Version History

Introduced in R2014b

expand all