LinuxCommandLibrary

matlab

Start the MATLAB environment

TLDR

Run without splash screen during startup

$ matlab -nosplash
copy

Execute a MATLAB statement
$ matlab -r "[matlab_statement]"
copy

Run a MATLAB script
$ matlab -r "run([path/to/script.m])"
copy

SYNOPSIS

matlab [options] [arguments]

PARAMETERS

-nodesktop
    Starts MATLAB without the Java desktop environment, running in the command-line interface. This is useful for server-side or scripted execution.

-nodisplay
    Starts MATLAB without displaying any X-Windows System, including the desktop. This option implies -nodesktop and is typically used on systems without a graphical display.

-batch script_name
    Executes the specified MATLAB script non-interactively and then exits. This is the recommended way to run MATLAB scripts in batch mode, particularly for automation. MATLAB exits with status 0 on success, or a non-zero status on error.

-r MATLAB_command
    Executes the specified MATLAB command or function. The command must be enclosed in double quotes if it contains spaces. MATLAB remains running after execution, unless an 'exit' command is included.

-sd directory
    Sets the initial working directory for the MATLAB session to the specified directory.

-logfile filename
    Redirects all output from the MATLAB command window, including errors and warnings, to the specified filename.

-nosplash
    Suppresses the display of the MATLAB splash screen during startup.

-singleUse
    Causes MATLAB to shut down automatically after the last MATLAB window is closed. Useful for automated tasks that launch GUI applications.

-version
    Displays the MATLAB version information and exits immediately.

DESCRIPTION

The matlab command is the primary entry point for starting the MATLAB application on a Linux system. MATLAB, short for MATrix LABoratory, is a proprietary multi-paradigm programming language and numerical computing environment developed by MathWorks. It is widely used in academia and industry for tasks such as matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, and Fortran.

When invoked without options, matlab typically launches the full interactive desktop environment. However, it provides a rich set of command-line options to control its behavior, allowing users to run scripts non-interactively, execute specific MATLAB commands, suppress the graphical user interface, or redirect output, making it highly suitable for batch processing, automated tasks, and server-side deployments.

CAVEATS

Using matlab requires a valid license, which must be correctly configured. Running MATLAB with the full desktop environment can be resource-intensive, requiring significant RAM and CPU. For remote access, X-forwarding (e.g., via SSH -X) is necessary to display the graphical desktop. When using -batch, ensure that the script handles its own exit logic, as MATLAB will only terminate after the script completes.

ENVIRONMENT VARIABLES

The behavior of MATLAB can be influenced by several environment variables. Notable ones include MATLABPATH, which specifies additional directories where MATLAB should look for functions and scripts, and LD_LIBRARY_PATH, which can be relevant for linking against external libraries.

EXIT STATUS

When run with -batch, the matlab command returns an exit status. A status of 0 typically indicates successful execution, while a non-zero status indicates that an error occurred during script execution or startup. This is crucial for integrating MATLAB into shell scripts and CI/CD pipelines.

HISTORY

MATLAB was first released by MathWorks in 1984, building upon earlier work by Cleve Moler. From its inception, the command-line interface has been a fundamental part of its operation, essential for both interactive use and non-interactive scripting. The evolution of the matlab command has focused on enhancing its capabilities for automated workflows, server deployments, and integration into larger computational systems, particularly with the introduction of options like -batch for robust script execution.

SEE ALSO

octave(1), python(1), R(1), scilab(1)

Copied to clipboard