Syntax for pyrunfile with multiple output variables?

조회 수: 52 (최근 30일)
Len Jacob
Len Jacob 2023년 1월 9일
편집: Les Beckham 2023년 1월 9일
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.

채택된 답변

Les Beckham
Les Beckham 2023년 1월 9일
편집: Les Beckham 2023년 1월 9일
This is the way to do that (note that ["A" "B"] is a string array as specified in the documentation for that argument):
[A, B] = pyrunfile("pytorch_model.py", ["A" "B"], X=Xpy, y=ypy)

추가 답변 (1개)

Les Beckham
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
Len Jacob 2023년 1월 9일
이동: Walter Roberson 2023년 1월 9일
This worked, thank you.
Les Beckham
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by