MATLAB: How to change directory of matlab script in linux command line

linuxmatlab in backgroundrun script in linux command line

I need to open matlab from a linux workspace and let it run a cript. The problem is, that my script is not in the home directory and I can't put it there. What I need to figure out is how to change the command so it will automatically run the script in the right directory.
matlab -nodisplay -r script.m
This command wont work because it wont find the script. Is there a way like
matlab -nodisplay -r ../test/test/test/script.m
to use something like that? It is hard to explain but I need to get it to work with a linux command (so no addpath or something like that possible). Thank you very much

Best Answer

matlab -nodisplay -r "try; run('../test/test/test/script.m'); catch ME; end; quit();"
Note:
  1. run() only applies to scripts, not functions.
  2. run internally cd's until the script is in the current directory. If the script needs to access files in the directory you start matlab from, then this is not the appropriate solution.