0

I have a Matlab function that returns a variable number of results. In Matlab I call it in the following way

>> [A, B] = func(C);

When I use mlab to wrap this call in Python I only get A

>>> result = mlab.func(C)

Pattern matching on the Python side (i.e. [A, B] = mlab.func(C)) is predictably ineffective.

How can I get all of the returned values from mlab? Is there some lower-level API I'm missing?

MRocklin
  • 55,641
  • 23
  • 163
  • 235

1 Answers1

0

You can read this tutorial https://pypi.python.org/pypi/mlab. After adding nout field in the parameter part, you can get multiple results.

mlab.svd(array([[1,2], [1,3]]))

array([[ 3.86432845], [ 0.25877718]])

Notice that we only got 'U' back -- that's because python hasn't got something like Matlab's multiple value return. Since Matlab functions can have completely different behavior depending on how many output parameters are requested, you have to specify explicitly if you want more than 1. So to get 'U' and also 'S' and 'V' you'd do:

U, S, V = mlab.svd([[1,2],[1,3]], nout=3)

William
  • 598
  • 4
  • 10