Main Content

Invoke MATLAB Functions that Return Multiple Outputs

Receive the Results as Individual Variables

The connection between a Python® client and a MATLAB® Production Server™ instance is encapsulated in a matlab.production_server.client.MWHttpClient object. When you are expecting multiple return values from the server and want each return value saved in a variable, invoke MATLAB functions directly using the client connection object.

result1,...resultN = my_client.archive_name.function_name(in_args,
                                                          nargout=nargs)
  • my_client — Name of client connection object

  • archive_name — Name of the deployable archive hosting the function

  • function_name — Name of the function to invoke

  • in_args — Comma-separated list of input arguments

  • nargs — Number of results expected from the server

Each variable is populated with a single return value.

For example, 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

Receive the Results as a Single Object

The connection between a Python client and a MATLAB Production Server instance is encapsulated in a matlab.production_server.client.MWHttpClient object. You invoke MATLAB functions directly using the client connection object.

results = my_client.archive_name.function_name(in_args, nargout=nargs)
  • my_client — Name of client connection object

  • archive_name — Name of the deployable archive hosting the function

  • function_name — Name of the function to invoke

  • in_args — Comma-separated list of input arguments

  • nargs — Number of results expected from the server

The variable is populated by a list containing all of the returned values.

For example, 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")
>>> copies = my_client.copier.copy("blue",10,nargout=2)
>>> print(copies)
["blue",10]

Related Topics