フィルターのクリア

matlab.engine function returns only the first output

9 ビュー (過去 30 日間)
clpi
clpi 2019 年 7 月 9 日
コメント済み: clpi 2019 年 7 月 9 日
Hello,
For a test, I have written a very simple matlab function that has two outputs:
function [y,z] = mat_func(x)
y = [2.0*x ,2.0*x] ;
z = [3.0*x, 3.0*x] ;
Then I wrote a python script which calls mat_func : [y,z] = eng.mat_func(2.0)
I got an error message "ValueError: need more than 1 value to unpack"
It works when I write: y= eng.mat_func(2.0) , but in this case of course I only get the first output, which is [4.0 4.0].
How can I get both outputs by calling the function from python ?
Thanks for any help !

採用された回答

Steven Lord
Steven Lord 2019 年 7 月 9 日
According to the "Return Multiple Output Arguments from MATLAB Function" section on this documentation page you need to call it with one output and an additional input that specifies the number of outputs you want. So something like this should work, though I haven't tried it myself:
yz = eng.mat_func(2.0, nargout=2)
  1 件のコメント
clpi
clpi 2019 年 7 月 9 日
Yes,it works ! Thamk you so much, I had forgotten about this "nargout" thing.
Have a good day!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by