System‎ > ‎

Command line

Unix / Linux / Ubuntu

Run Matlab script from command line

Run simple Matlab commands direct on Ubuntu command line

% multiply 3  with 4
matlab -nodisplay -r '3*4 , exit'
    12

% get square root of number 64
matlab -nodisplay -r 'sqrt(64) , exit'
     8

% print "Hello World!"
matlab -nodisplay -r 'disp("Hello World!") , exit'
  Hello World!

Run own Matlab script on Ubuntu command line

% run own script (.m file) on Ubuntu command line (use script-name without ending ".m")
matlab -nodisplay  -r myscript,exit
  Hello World

% run script and save output in separate log file
matlab -nodisplay  -r myscript,exit  -logfile output.txt


% run own script function (.m file) that multiplies two input arguments
matlab -nodisplay  -r 'z = myfunction(3,4); disp(z); exit'
    12

Matlab start options

-nodesktop   avoids starting the complete Matlab desktop editor
-nosplash    skips the splash screen (the little blue matlab logo starting window)
-nojvm       starts matlab without Java
-noawt       starts matlab without Java GUI, but loads Java for data processing

see -help for more options
matlab -help
    -h|-help                - Display arguments.
    -n                      - Display final environment variables,
                              arguments, and other diagnostic
                              information. MATLAB is not run.
    -e                      - Display ALL the environment variables and
                              their values to standard output. MATLAB
                              is not run. If the exit status is not
                              0 on return then the variables and values
                              may not be correct.
    v=variant               - Start the version of MATLAB found
                              in bin/glnxa64/variant instead of bin/glnxa64.
    -c licensefile          - Set location of the license file that MATLAB
                              should use.  It can have the form port@host or
                              be a colon separated list of license files.
                              The LM_LICENSE_FILE and MLM_LICENSE_FILE
                              environment variables will be ignored.
    -display Xdisplay       - Send X commands to X server display, Xdisplay.
                              Linux only.
    -nodisplay              - Do not display any X commands. The MATLAB
                              desktop will not be started. However, unless
                              -nojvm is also provided the Java virtual machine
                              will be started.
    -noFigureWindows        - Disables the display of figure windows in MATLAB.
    -nosplash               - Do not display the splash screen during startup.
    -softwareopengl         - Force MATLAB to start with software OpenGL
                              libraries. Not available on macOS.
    -nosoftwareopengl       - Disable auto-selection of software OpenGL
                              when a graphics driver with known issues is detected.
                              Not available on macOS.
    -debug                  - Provide debugging information especially for X
                              based problems. Linux only.
    -desktop                - Allow the MATLAB desktop to be started by a
                              process without a controlling terminal. This is
                              usually a required command line argument when
                              attempting to start MATLAB from a window manager
                              menu or desktop icon.
    -nodesktop              - Do not start the MATLAB desktop. Use the current
                              terminal for commands. The Java virtual machine
                              will be started.
    -singleCompThread       - Limit MATLAB to a single computational thread.
                              By default, MATLAB makes use of the multithreading
                              capabilities of the computer on which it is running.
    -nojvm                  - Shut off all Java support by not starting the
                              Java virtual machine. In particular the MATLAB
                              desktop will not be started.
    -jdb [port]             - Enable remote Java debugging on port (default 4444)
    -r MATLAB_command       - Start MATLAB and execute the MATLAB_command.
    -sd folder              - Set the MATLAB startup folder to folder,
                              specified as a string.
    -useStartupFolderPref   - Set the MATLAB startup folder to the value
                              specified by the Initial working folder option
                              in the General Preferences panel.
    -logfile log            - Make a copy of any output to the command window
                              in file log. This includes all crash reports.
    -Ddebugger [options]    - Start debugger to debug MATLAB.
    -nouserjavapath         - Ignore custom javaclasspath.txt and javalibrarypath.txt files.




Subpages (1): Error
ċ
myfunction.m
(0k)
Matthias Scholz,
Aug 31, 2018, 7:24 AM
ċ
myscript.m
(0k)
Matthias Scholz,
Aug 31, 2018, 5:33 AM