Calling MATLAB file from Linux using MCR

조회 수: 2 (최근 30일)
Mohamed AKI Ahmed
Mohamed AKI Ahmed 2023년 4월 13일
답변: Manoj Mirge 2023년 4월 20일
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에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by