Borrar filtros
Borrar filtros

Calling MATLAB file from Linux using MCR

4 visualizaciones (últimos 30 días)
Mohamed AKI Ahmed
Mohamed AKI Ahmed el 13 de Abr. de 2023
Respondida: Manoj Mirge el 20 de Abr. de 2023
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

Respuestas (1)

Manoj Mirge
Manoj Mirge el 20 de Abr. de 2023
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.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by