3

I have a Matlab function that I'm calling from a python script:

import matlab.engine

eng = matlab.engine.start_matlab()
t = (1,2,3)
z = eng.tstFnc(t)
print z

The function tstFnc is as follows:

function [ z ] = tstFnc( a, b, c )
z = a + b + c

This does not work, however, as Matlab receives one input instead of three. Could this be made to work?

Note: this is a simplified case of what I want to do. In the actual problem I have a variable number of lists that I pass into a Matlab function, which is interpreted in the Matlab function using varargin.

sodiumnitrate
  • 2,899
  • 6
  • 30
  • 49

1 Answers1

3

As notes in the comments, the arguments need to be applied instead of passed as a tuple of length 1.

z = eng.tstFnc(*t)

This causes a call to tstFnc with len(t) arguments instead of a single tuple argument. Similarly you could just pass each argument individually.

z = eng.tstFnc(1, 2, 3)

Pyrce
  • 8,296
  • 3
  • 31
  • 46