Skip to main content

Executing Matlab from command line

Passing an argument from command line to Matlab script can be tricky because

There are two solutions I can think of right now:
  1. Set the environment variables before starting Matlab
    1. Using BASH shell, one may set the environment variable using the command: a=1;b=2
    2. Start Matlab using the command: matlab -nojvm -nosplash
    3. Inside matlab script one can get those variables using the command: a=getenv(a); b=getenv(b).
  2. Using the argument "-r"
    1. matlab -nojvm -nosplash -r "a=1;b=2; aScriptName;"

Comments