How to pass Matlab variables to pyrunfile?
13 ビュー (過去 30 日間)
古いコメントを表示
My Matlab script:
clc
clear all
close all
% Define Matlab variable
var01 = 'Some string';
pyrunfile("pyScript.py", var01)
The pyScript.py:
import sys
arg01 = sys.argv[1]
print(arg01)
The error I'm getting when I run it:
Error using <string>><module>
Python Error: IndexError: list index out of range
What would be the proper way to pass Matlab variable to a python script that can be assigned with sys.argv[1]?
Thank you,
0 件のコメント
採用された回答
Angelo Yeo
2023 年 7 月 3 日
clc
clear all
close all
% Define Matlab variable
var01 = 'Some string';
pyrunfile("pyScript.py '" + var01 + "'")
2 件のコメント
Angelo Yeo
2023 年 7 月 5 日
I am happy that the solution worked for you 😊 Another reason why I left the doc link is that someone else can see this post later and refer to the official doc. Have a good day!
その他の回答 (0 件)
参考
カテゴリ
Help Center および 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!