determine name of m file that is running when running it from a command line on a linux cluster

2 visualizzazioni (ultimi 30 giorni)
I'm trying to determine the name of an m file that I'm running. I am able to use mfilename when doing this with the Matlab GUI on a windows machine. However when I run the same m file from a command line on a linux cluster, mfilename returns <0x0 empty char array>. Is there another solution needed for this case and ideally one that works for both cases? Below is the basic command setup I am using for the job cluster which has another line that sets the MatlabScript variable. The mfilename is desired because it is used to set other names as well as to find associated files while keeping the user from having to modify an extra line in a large m file (and potentially forgetting) .
MatlabFlags="-nosplash -nodesktop -nodisplay -glnxa64 < $MatlabScript"
matlab $MatlabFlags >>job.log 2>&1

Risposte (2)

Steven Lord
Steven Lord il 23 Gen 2020
That answer mfilename returns is correct. You're not running a MATLAB program file. You're piping the contents of a MATLAB program file into MATLAB, which is different. If you want to tell MATLAB to run a particular program file, start it with either the -r or the -batch startup options listed on this documentation page.
Actually, -batch was introduced in release R2019a according to the Release Notes so you won't be able to use it since this is tagged with release R2018b, but -r should help.
Alternately, you could try using getenv to retrieve the environment variable containing the name of the script you're piping into MATLAB.

Jesse Gerdes
Jesse Gerdes il 24 Gen 2020
I tried a few orderings below with 2018 and 2019a. They failed. What am I missing here? The errors were 'no matlab command specified for -r command line argument', 'invalid use of operator', and 'no such file or directory'. Is the last order correct? Does the variable $MatlabScript need to be the absolute path to the file or the relative filename assuming the command line is opened in location that the file is at?
MatlabFlags="-r -nosplash -nodesktop -nodisplay -glnxa64 < $MatlabScript"
MatlabFlags="-nosplash -nodesktop -nodisplay -glnxa64 -r < $MatlabScript"
MatlabFlags="-nosplash -nodesktop -nodisplay -glnxa64 < -r $MatlabScript"
matlab $MatlabFlags >>job.log 2>&1

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by