Syntax for pyrunfile with multiple output variables?
显示 更早的评论
I am calling a python script from matlab using pyrunfile. The following works:
A = pyrunfile("pytorch_model.py", "A", X=Xpy, y=ypy)
B = pyrunfile("pytorch_model.py", "B", X=Xpy, y=ypy)
The following doesn't:
[A, B] = pyrunfile("pytorch_model.py", "A B", X=Xpy, y=ypy)
[A, B] = pyrunfile("pytorch_model.py", "A, B", X=Xpy, y=ypy)
Error: One or more output arguments not assigned during call to "pyrunfile".
What is the correct syntax for returning multiple variables? The documentation https://www.mathworks.com/help/matlab/ref/pyrunfile.html states that doing so is possible but does not show an example of how to format the string array containing the name of the python variables we want to return.
采纳的回答
更多回答(1 个)
Les Beckham
2023-1-9
移动:Walter Roberson
2023-1-9
Did you try this?
[A, B] = pyrunfile("pytorch_model.py", ["A" "B"], X=Xpy, y=ypy)
Note that ["A" "B"] is a string array as specified by the documentation for that argument.
2 个评论
Len Jacob
2023-1-9
移动:Walter Roberson
2023-1-9
Les Beckham
2023-1-9
移动:Walter Roberson
2023-1-9
You are quite welcome. I've posted this as an Answer so people looking for this in the future will know it has been solved. I'd appreciate it if you "Accept" the answer. Thanks.
类别
在 帮助中心 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!