Invoke Packaged MATLAB Functions
The connection between a Python® client and a MATLAB®
Production Server™ instance is encapsulated in a
matlab.production_server.client.MWHttpClient
object. You invoke
deployed MATLAB functions using the client connection object.
result1,...resultN = my_client.archive_name.function_name(in_args, nargout=nargs)
my_client
— Name of client connection objectarchive_name
— Name of the deployable archive hosting the functionfunction_name
— Name of the function to invokein_args
— Comma-separated list of input argumentsnargs
— Number of results expected from the server. The default value is 1.
Note
If the function to invoke returns an output, each variable on the left side of the
function call is populated with a single return value. If you provide less than
nargs
variables on the left side of the function call, the last
listed variable contains a list of the remaining results. For example,
result1, result2 = myMagic.triple(5,nargout=3)
leaves result1
containing a single value and
result2
containing a list with two values.
Invoke MATLAB Functions that Return Multiple Outputs
Receive Multiple Results as Individual Variables
To invoke the MATLAB function c1,c2 = copy(o1,o2)
from the deployable
archive copier
, use this code:
>>> import matlab
>>> from production_server import client
>>> my_client = client.MWHttpClient("http://localhost:9910")
>>> c1,c2 = my_client.copier.copy("blue",10,nargout=2)
>>> print(c1)
"blue"
>>> print(c2)
10
The variables c1
and c2
are populated with a
single return value.
Receive Multiple Results as Single Object
To invoke the MATLAB function copies = copy(o1,o2)
from the deployable
archive copier
, use this code:
>>> import matlab
>>> from production_server import client
>>> my_client = client.MWHttpClient("http://localhost:9910")
>>> copies = my_client.copier.copy("blue",10,nargout=2)
>>> print(copies)
["blue",10]
The variable copies
is populated with a list containing all of
the returned values.
Invoke MATLAB Functions that Return Zero Outputs
To invoke the MATLAB function mutate(m1, m2, m3)
from the deployable archive
mutations
, you use this code:
import matlab
from production_server import client
my_client = client.MWHttpClient("http://localhost:9910")
m1 = matlab.double(...)
m2 = matlab.double(...)
m3 = matlab.double(...)
my_client.mutations.mutate(m1,m2,m3)
Invoke MATLAB Functions that Return Single Output
To invoke the MATLAB function result = mutate(m1, m2, m3)
from the
deployable archive mutations
, you use this code:
import matlab
from production_server import client
my_client = client.MWHttpClient("http://localhost:9910")
m1 = matlab.double(...)
m2 = matlab.double(...)
m3 = matlab.double(...)
result = my_client.mutations.mutate(m1,m2,m3)
See Also
matlab.production_server.client.MWHttpClient