Azzera filtri
Azzera filtri

Is it possible to pass a MATLAB file that requires an input argument to MATLAB in batch mode under UNIX?

17 visualizzazioni (ultimi 30 giorni)

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 27 Gen 2010
You cannot pass a MATLAB file that requires an input argument to MATLAB in batch mode. This is not possible because when you use redirection in UNIX to pass a MATLAB file to be run in batch mode, MATLAB executes the file by reading each line as if it were typed at the MATLAB prompt. MATLAB files that require input arguments must be declared as functions, and you cannot declare a function at the MATLAB prompt.
To work around this you can create an environment variable that will contain the input argument and use the MATLAB GETENV function. For example, create the environment variable with the input argument
setenv VAR 10
and retrieve the input argument using GETENV
inputArg = getenv('VAR');
inputArg = str2num(inputArg);
myFunction(inputArg)
This will allow you to pass input arguments when using batch mode. Additionally, this can be incorporated into a shell script.
Alternatively, you can write a shell script that will take your input data file and write the necessary MATLAB file you want based on the input data file. Then, when you use redirection to run the file in batch mode, specify the name of the MATLAB file you created with your shell script.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by