matlab.engine.MatlabEngine
Pythonobject usingMATLABas computational engine withinPythonsession
Description
TheMatlabEngine
class uses a MATLAB®process as a computational engine for Python®. You can call MATLAB functions as methods of aMatlabEngine
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 aMatlabEngine
object.
Creation
Thematlab.engine.start_matlab
method creates aMatlabEngine
object each time it is called. There is no need to callmatlab.engine.MatlabEngine()
to createMatlabEngine
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
Thematlab::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 aMatlabEngine
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 asmatlabfunc
isprime
orsqrt
). 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 |