Pyrunfile input from Matlab workspace
13 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I'm trying to get data via a python code using a dll. I already have access but only for specific files, running with
Outvars = pyrunfile(file input, outputs)
Now I want the filname that is used in python as an input parameter from matlab like:
fileName = 'C:/...';
Outvars = pyrunfile("file" fileName, outputs);
Is this somehow possible?
Another idea is not to use pyrunfile but creating a module in python and then calling the functions with py.my_function() but then I don't know how to initialize the database-access with the changing fileName. So I would still need to change the filename in the python module script.
0 件のコメント
回答 (1 件)
Infinite_king
2023 年 10 月 5 日
Hi,
I understand that you want to execute a Python script from MATLAB and pass a filename stored in the MATLAB workspace as an input parameter to the Python script.
You can achieve this by using ‘pyrunfile’ function. The first argument of ‘pyrunfile’ function should be a string containing python script name followed by input arguments. Refer the below code snippet,
% file name stored in MATLAB variable
file_name = "<path>";
% python file name
python_file_name = "python_prog.py";
% create a string with python script name followed by input arguments
str = python_file_name + " " + file_name;
% displaying the string
disp(str);
% calling python file by passing matlab variable as argument
pyrunfile(str);
The python script will receive these inputs as strings. For example let’s consider above example, the script ‘python_prog’ will receive ‘<path>’ as a string.
For more information on how to use ‘pyrunfile’ function, refer the following documentation.
Hope this is helpful.
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!