Main Content

matlab (Linux)

Start MATLAB program from Linux system prompt

Description

matlab is a Bourne shell script that launches the MATLAB® program from a Linux® system prompt. Here the term matlab refers to this script and MATLAB refers to the program.

The matlab script:

  • Determines the MATLAB root folder, the value returned by the matlabroot function

  • Processes command-line options, if any

  • Reads the MATLAB start-up file, .matlab7rc.sh

  • Sets MATLAB environment variables

example

matlab option1 ... optionN launches MATLAB with the specified start-up options.

Alternatively, assign start-up options in the MATLAB .matlab7rc.sh Start-up File. Modifying the .matlab7rc.sh file defines start-up options every time you start MATLAB.

MATLAB uses the Java® Virtual Machine (JVM®) software to run the desktop and to display graphics. The -nojvm option enables you to start MATLAB without the JVM. Using this option minimizes memory usage and improves initial start-up speed, but restricts functionality.

Input Arguments

expand all

One or more start-up options, specified as strings corresponding to valid start-up options from the following tables.

Mode Options

OptionResult
-desktop

Start MATLAB without a controlling terminal. Use this option when you start MATLAB from a window manager menu or desktop icon.

-nodesktop

Run the JVM software without opening the MATLAB desktop. You can use development environment tools by calling them as functions.

To run in batch processing mode, use the -batch option.

If you use the > constructor to pipe to MATLAB, then the nodesktop option is used automatically.

MATLAB provides a command window-only interface in the desktop environment. On the Home tab, click Layout. Then, under Select Layout, select Command Window Only.

For a more accessible alternative to using MATLAB with the -nodesktop option, use the Command Window Only layout in MATLAB Online™ instead. Using the Command Window Only layout in MATLAB Online gives you access to more keyboard shortcuts and, when needed, the full functionality of the MATLAB desktop. To select the Command Window Only layout in MATLAB Online, go to the Home tab, and in the Environment section, click the Layout button and then select Command Window Only.

-nojvm

Start MATLAB without the JVM software. Features that require Java software (such as the desktop tools and graphics) are not supported.

Display Options

OptionResult
-noFigureWindows

Disable the display of figure windows in MATLAB.

-nosplash

Do not display the splash screen during startup.

-nodisplay

Start the JVM software without starting the MATLAB desktop. This option does not display X commands. It overrides the DISPLAY environment variable.

-display xDisp

Send X commands to X Window Server display xDisp. This option overrides the DISPLAY environment variable.

Set Initial Working Folder

The initial working folder is the current folder when MATLAB starts. For more information, see MATLAB Startup Folder.

OptionResult

-sd folder

Set the MATLAB folder to folder, specified as a string.

Example: matlab -sd "C:\work"

-useStartupFolderPref

Set the MATLAB folder to the value specified by the Initial working folder preference, located in the General Preferences page of the Preferences.

Specify MATLAB Version

OptionResult
v=variant

Start the version of MATLAB in the bin/arch/variant folder instead of the bin/arch folder, where:

  • arch is the system architecture, the value returned by the computer('arch') function

  • variant is a string representing a MATLAB version

Debugging Options

OptionResult

-logfile filename

Copy Command Window output, including error reports, into filename, specified as a string.

Example: -logfile output.log

-n

Display, without starting MATLAB, the final values of the environment variables and arguments passed to the MATLAB executable. This option also displays other diagnostic information for use when working with a Technical Support Representative.

-e

Display, without starting MATLAB, all environment variables and their values to standard output. If the exit status is not 0 on return, then the variables and values might not be correct.

-Ddebugger debugopts

Start MATLAB in debug mode. This option uses the debugger program name, debugger, specified as a string, for example, gdb, lldb, or dbx. You can specify the full path to the debugger. This option must be the first option in the matlab script.

Debugger program command-line options, debugopts, specified as a string of valid options for debugger. See your debugger documentation for details. Do not use any other matlab script options when using debugopts.

Do not add a space between D and debugger.

Example: -Dgdb

-jdb portnumber

Enable use of the Java debugger. The Java debugger uses the default portnumber value 4444 to communicate with MATLAB.

The port number is optional. However, to use the Java debugger while running multiple MATLAB sessions, you must specify a port number. The portnumber value must be an integer in the range 0–65535. The integer cannot be reserved or currently in use by another application on your system.

-debug

Display information for debugging X-based problems. Use this option only when working with a Technical Support Representative from MathWorks, Inc.

Execute MATLAB Script or Function

OptionResult

-batch statement

Execute MATLAB script, statement, or function non-interactively. MATLAB:

  • Starts without the desktop

  • Does not display the splash screen

  • Executes statement

  • Displays figure windows, unless combined with the -noFigureWindows or -nodisplay options

  • Displays user-generated modal dialog boxes, but does not display unprompted modal dialog boxes

  • Disables changes to preferences

  • Disables toolbox caching

  • Logs text to stdout and stderr

  • Exits automatically with exit code 0 if statement executes successfully. Otherwise, MATLAB terminates with a non-zero exit code.

statement is MATLAB code enclosed in double quotation marks. If statement is the name of a MATLAB function or script, do not specify the file extension. Any required file must be on the MATLAB search path or in the startup folder.

Use the -batch option in non-interactive scripting or command line workflows. Do not use this option with the -r option.

To test if a session of MATLAB is running in batch mode, call the batchStartupOptionUsed function.

Example: -batch "myscript"

-r statement

Execute the MATLAB statement. Use this option for interactive workflows. Do not use this option with the -batch option.

Note

To set the initial working folder, use the -sd option. For example:

-sd folder

Example: -r "disp(['Current folder: ' pwd])"

Example: -r "myscript"

Use Single Computational Thread

By default, MATLAB uses the multithreading capabilities of the computer on which it is running.

OptionResult
-singleCompThread

Limit MATLAB to a single computational thread. This option is for numerical computations only.

Disable Searching Custom Java Class Path

OptionResult
-nouserjavapath

Disable use of javaclasspath.txt and javalibrarypath.txt files. For more information, see Specifying Java Startup Options.

OpenGL Library Options

These options control the use of software OpenGL® libraries when MATLAB detects a graphics driver with known issues. For more information, see Graphics Features That Have Specific Requirements.

In a future release, these options will be removed. For more information, see Version History.

OptionResult
-softwareopengl

Force MATLAB to start with software OpenGL libraries.

-nosoftwareopengl

Disable auto-selection of OpenGL software.

Specify License File

OptionResult

-c license

Use the specified license file, license, specified as a string, a colon-separated list of license file names, or a port@host entry. For more information, see Update or Modify Network License Files.

Help Options

OptionResult
-h

Display startup options without starting MATLAB.

-help

Same as -h option.

Examples

expand all

matlab -nodisplay
matlab -r "disp(['Current folder: ' pwd])"

More About

expand all

Version History

expand all