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

回答(1 个)

Manoj Mirge
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.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by