invoke a packaged matlab function -凯发k8网页登录

main content

invoke a packaged 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 matlab function with 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 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 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]

invoke a matlab function in the background

to invoke a matlab function sumwrap from the package sumwrap 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]])

related topics

网站地图