determine name of m file that is running when running it from a command line on a linux cluster
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Steven Lord
on 23 Jan 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.
0 Comments
Jesse Gerdes
on 24 Jan 2020
1 Comment
Steven Lord
on 24 Jan 2020
You don't need the pipe in. Something like this should work
matlab -r $MatlabScript -nosplash -nodesktop -nodisplay -glnxa64
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!