Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Invoke a Compiled MATLAB Function

Invoke 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 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 a MATLAB Function with 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([1,2,3])
m2 = matlab.double([10,20,30])
m3 = matlab.double([100,200,300])

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

Invoke a MATLAB Function with 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([1,2,3])
m2 = matlab.double([10,20,30])
m3 = matlab.double([100,200,300])

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 Topics

Was this topic helpful?