matlab.engine.MatlabEngine
Python object using MATLAB as computational engine within Python session
Description
The MatlabEngine
class uses a MATLAB® process as a computational engine for Python®. You can call MATLAB functions as methods of a MatlabEngine
object because the
functions are dynamically invoked when you call them. You also can call functions and scripts
that you define. You can send data to, and retrieve data from, the MATLAB workspace associated with a MatlabEngine
object.
Creation
The matlab.engine.start_matlab
method creates a
MatlabEngine
object each time it is called. There is no need to call
matlab.engine.MatlabEngine()
to create MatlabEngine
objects of your own.
Attributes
Attribute | Description |
---|---|
| Python dictionary containing references to MATLAB variables. You can assign data to, and get data from, a MATLAB variable through the |
Methods
Public Methods
The matlab::engine::MATLABEngine
class provides these methods.
matlab.engine.start_matlab
— Start MATLABmatlab.engine.find_matlab
— Find shared MATLAB sessions to connect to MATLAB Engine for Pythonmatlab.engine.connect_matlab
— Connect to shared MATLAB session
Specialized Operators and Functions
You can call any MATLAB function as a method of a MatlabEngine
object. The engine
dynamically invokes a MATLAB function when you call it. The syntax shows positional, keyword, and output
arguments of a function call.
ret =
MatlabEngine.
matlabfunc
(*args
,nargout=1,background=False,stdout=sys.stsdout,stderr=sys.stderr)
Replace
with the name of any
MATLAB function (such as matlabfunc
isprime
or sqrt
).
Replace
with input arguments for the
MATLAB function you call. The keyword arguments specify:*args
The number of output arguments the function returns
Whether the engine calls the function asynchronously
Where the engine sends standard output and standard error coming from the function
Specify keyword arguments only when specifying values that are not the default values shown in the syntax.
Argument | Description | Python Type |
---|---|---|
| Input arguments to MATLAB function, specified as positional arguments | Any Python types that the engine can convert to MATLAB types |
Argument | Description | Python Type |
---|---|---|
| Number of output arguments from MATLAB function |
|
| Flag to call MATLAB function asynchronously
|
|
| Standard output |
|
| Standard error |
|
Output Type | Description | Required Keyword Arguments |
---|---|---|
Python variable | One output argument from MATLAB function | Default values |
| Multiple output arguments from MATLAB function |
|
| No output argument from MATLAB function |
|
| A placeholder for output arguments from asynchronous call to MATLAB function |
|
Exceptions
Exception | Description |
---|---|
MatlabExecutionError | Function call fails to execute |
RejectedExecutionError | MATLAB engine terminated |
SyntaxError | Syntax error in a function call |
TypeError | Data type of an input or output argument not supported |