Invoke a PackagedMATLABFunction
Invoke a compiled MATLAB®function using the Python®object returned from theinitialize()
function.
result1,...resultN =my_client.function_name(in_args, nargout=娜戈,stdout=out_stream, stderr=err_stream)
my_client
— Name of object returned frominitialize()
function_name
— Name of the function to invokein_args
— Comma-separated list of input argumentsnargs
— Number of expected results. The default value is1
.out_stream
— PythonStringIO
object receiving the console output. The default is to direct output to the console.err_stream
— PythonStringIO
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 thannargs
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)
leavesresult1
containing a single value andresult2
containing a list with two values.
InvokeMATLABFunction with Single Output
To invoke the MATLAB functionresult = mutate(m1, m2, m3)
from the packagemutations
, 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)
InvokeMATLABFunction with Zero Outputs
To invoke the MATLAB functionmutate(m1,m2,m3)
from the packagemutations
, 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 functionc1,c2 = copy(o1,o2)
from the packagecopier
, 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 Single Object
To invoke the MATLAB functioncopies = copy(o1,o2)
from the packagecopier
, use this code:
>>> import copier >>> import matlab >>> myCopier = copier.initialize() >>> copies = myCopier.copy("blue",10,nargout=2) >>> print(copies) ["blue",10]
Invoke aMATLABFunction in the Background
To invoke a MATLAB functionsumwrap
from the packagesumwrap
asynchronously, use this code:
>>> import sumwrap >>> import matlab >>> sw = sumwrap.initialize() >>> a = matlab.double([[1, 2],[3, 4]]) >>> future = sw.sumwrap(a, 1, background=True) >>> future.result() matlab.double([[4.0,6.0]])