Evaluate a Compiled MATLAB Function

Evaluate a compiled MATLAB® function using the Python® object returned from the initialize() function.

result1,...resultN = my_client.function_name(in_args, nargout=nargs,
                                             stdout=out_stream,
                                             stderr=err_stream)
  • my_client — Name of object returned from initialize()

  • function_name — Name of the function to invoke

  • in_args — Comma-separated list of input arguments

  • nargs — Number of expected results. The default value is 1.

  • out_stream — Python StringIO object receiving the console output. The default is to direct output to the console.

  • err_stream — Python StringIO object receiving the error output. The default is to direct output to the console.

Each variable on the left side of the function call is populated with a single return value.

    Note:   If you provide less than nargs variables on the left side of the function call, the last listed variable will contain 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 a MATLAB Function that Returns a Single Output

To invoke the MATLAB function result = mutate(m1, m2, m3) from the package mutations, you use this code:

import mutations
import matlab

myMutator = mutations.initialize()

m1 = matlab.double(...)
m2 = matlab.double(...)
m3 = matlab.double(...)

result = myMutator.mutate(m1,m2,m3)

Invoke a MATLAB Function that Returns Zero Outputs

To invoke the MATLAB function mutate(m1,m2,m3) from the package mutations, you use this code:

import mutations
import matlab

myMutator = mutations.initialize()

m1 = matlab.double(...)
m2 = matlab.double(...)
m3 = matlab.double(...)

myMutator.mutate(m1,m2,m3,nargout=0)

Receive Multiple Results as Individual Variables

To invoke the MATLAB function c1,c2 = copy(o1,o2) from the package copier, use this code:

>>> import copier
>>> import matlab
>>> myCopier = copier.initialize()
>>> c1,c2 = myCopier.copy("blue",10,nargout=2)
>>> print(c1)
"blue"
>>> print(c2)
10

Receive Multiple Results as a Single Object

To invoke the MATLAB function copies = copy(o1,o2) from the package copier, use this code:

>>> import copier
>>> import matlab
>>> myCopier = copier.initialize()
>>> copies = myCopier.copy("blue",10,nargout=2)
>>> print(copies)
["blue",10]

Related Examples

Was this topic helpful?