Calling MATLAB file from Linux using MCR
2 ビュー (過去 30 日間)
古いコメントを表示
I have a MATLAB file that is called "run_mycode.m", This code is a function that takes 4 arguments(one boolean, two empty strings, and one mat file). I want to call this function from a Python script on Linux using MCR (I don't have MATLAB on that machine so I'm using MCR). I tried the following:
from subprocess import call
mypart = /mycomputer/part.mat
mcr_path = '/mycomputer/matlab/MATLAB_Compiler_Runtime/v91'
arg = '1 "" "" ' + mypart
cmd = 'run_mycode.sh ' + mcr_path + " " + arg
call(cmd, shell=True)
However, I get the following result:
/bin/sh: run_mycode.sh: command not found
0 件のコメント
回答 (1 件)
Manoj Mirge
2023 年 4 月 20 日
Hi ,
Although you are in the same directory as the “run_mycode.sh” file, Bash could not find this file. Because the current directory isn't in your $PATH variable of Linux bash.
In Linux, UNIX and related operating systems, “.” denotes the current directory. Since you want to run a file in your current directory and that directory is not in your $PATH, you need the “./” bit to tell the shell where the executable is. So, ./run_mycode.sh means run the executable called run_mycode.sh that is in this directory.
Therefore, you need to specify the relative or absolute path to the file so that shell knows where our executable file is.
Regarding your situation, code would look like this:
from subprocess import call
mypart = /mycomputer/part.mat
mcr_path = '/mycomputer/matlab/MATLAB_Compiler_Runtime/v91'
arg = '1 "" "" ' + mypart
cmd = './run_mycode.sh ' + mcr_path + " " + arg % Just add ./ before
% run_mycode.sh
call(cmd, shell=True)
Hope this helps.
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!