matlab (macOS) - Start MATLAB program from macOS Terminal - MATLAB (original) (raw)

Start MATLAB program from macOS Terminal

Syntax

Description

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

The matlab script is located in the MATLAB application package,/Applications/_`matlabroot`_/MATLAB_ _`release`_.app/bin, where matlabroot is the name of the folder in which you installed MATLAB and release is the MATLAB release number.

The matlab script:

example

matlab `option1 ... optionN` starts MATLAB with the specified startup options.

Alternatively, assign startup options in the MATLAB.matlab7rc.sh Startup File. Modifying the .matlab7rc.sh file defines startup options every time you start MATLAB. On macOS platforms, the .matlab7rc.sh file applies only when starting MATLAB from Terminal. The file does not apply when starting MATLAB by double-clicking the MATLAB icon in the Applications folder.

The -nojvm option starts MATLAB without loading the JVM®. Functionality that requires Java® will not be available in this session.

example

Input Arguments

expand all

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

Mode Options

Option Result
-desktop Start MATLAB without a controlling terminal. Use this option when you start MATLAB from a window manager menu or desktop icon.
-nodesktop Run MATLAB without opening the desktop. You can use development environment tools by calling them as functions. For example, call the edit function to open the Editor. 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.To ensure that output displays as intended, make sure that your macOS Terminal uses a monospaced font.For a more accessible alternative to using MATLAB with the -nodesktop option, use the Command Window Only layout instead. Using the Command Window Only layout gives you access to more keyboard shortcuts and, when needed, the full functionality of the MATLAB desktop. To select the Command Window Only layout, go to theHome tab, and in the Environment section, click the Layout button and then select . (since R2025a)
-nojvm Start MATLAB without loading the JVM software in the session. Features that require Java software are not supported.

Display Options

Option Result
-noFigureWindows Disable the display of figure windows in MATLAB.
-nodisplay Suppress desktop tools and graphics.

Set Initial Working Folder

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

Option Result
-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 setting, located in the General Settings page of the Settings window.

Specify MATLAB Version

Option Result
v=variant Start the version of MATLAB in thebin/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

Option Result
-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.
-D_debugger_ 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 thematlab 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 betweenD and debugger.Example:-Dlldb
-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.

Execute MATLAB Script or Function

Option Result
-batch_statement_ Execute MATLAB script, statement, or function non-interactively. MATLAB:Starts without the desktopDoes not display the splash screenExecutes statement_Displays figure windows, unless combined with the-noFigureWindows or -nodisplay optionsDisables changes to settingsDisables toolbox cachingLogs text to stdout and stderrExits 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.If you run code that creates dialog boxes that require user input, MATLAB throws an error.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.NoteTo 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.

Option Result
-singleCompThread Limit MATLAB to a single computational thread. This option is for numerical computations only.

Disable Searching Custom Java Class Path

Specify License File

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

Help Options

Option Result
-h Display startup options without starting MATLAB.
-help Same as -h option.

Examples

expand all

Move to the bin folder within the application package for MATLAB installed in a folder named MyMATLAB.

cd /Applications/MyMATLAB/MATLAB_R2015a.app/bin

Preface the matlab script with ./ characters.

Start MATLAB R2015a from any Terminal folder by specifying the full path name. Assume MATLAB is installed in a folder named MyMATLAB.

/Applications/MyMATLAB/MATLAB_R2015a.app/bin/matlab

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

More About

expand all

The .matlab7rc.sh shell script contains variable definitions used by the matlab script. To redefine variables defined in thematlab script, modify the .matlab7rc.sh file. The.matlab7rc.sh file applies only when starting MATLAB from Terminal; it does not apply when starting MATLAB by double-clicking the MATLAB icon in the Applications folder.

matlab looks in these folders for the first occurrence of.matlab7rc.sh in the following order:

  1. Current folder
  2. Home folder ($HOME)
  3. matlabroot/bin folder

To edit the .matlab7rc.sh file, use the template located in the_matlabroot_/bin folder.

The following table lists the variables. For more information, see the comments in the.matlab7rc.sh file.

.matlab7rc.shVariable Definition and Standard Assignment Behavior
ARCH Machine architectureMATLAB checks these values in this order: The value ARCH passed with the -arch or-arch/ext argument to the script.The value of the environment variable MATLAB_ARCH.
DYLD_LIBRARY_PATH Final Load library pathThe final value is normally a colon-separated list of four sublists, each of which could be empty. The sublists are: Defined in .matlab7rc.sh as LDPATH_PREFIX Computed in the script and includes folders inside the MATLAB root folder and relevant Java foldersContains any nonempty value of DYLD_LIBRARY_PATH from the environment possibly augmented in .matlab7rc.sh Defined in .matlab7rc.sh asLDPATH_SUFFIX
MATLAB MATLAB root folder
MATLABPATH MATLAB search pathThe final value is a colon-separated list with theMATLABPATH from the environment prepended to a list of computed defaults. At startup, you can add subfolders of userpath to the MATLAB search path. See userpath for details.
SHELL Shell to use with MATLAB “!” or unix commandsThis value is taken from the environment, unlessSHELL is reset in .matlab7rc.sh.The default .matlab7rc.sh file does not resetSHELL.
MATLAB_SHELL Shell to use instead of SHELLMATLAB checks for MATLAB_SHELL first and, if empty or not defined, checks SHELL. If SHELL is also empty or not defined, MATLAB uses the Bourne shell, /bin/sh.Use an absolute path for the value of MATLAB_SHELL, that is,/bin/sh, not simply sh. The default.matlab7rc.sh file does not reference or setMATLAB_SHELL.
TOOLBOX Path of the toolbox folderValue in the environment, if not emptyValue of TOOLBOX in .matlab7rc.sh, if resetValue of matlabroot/toolbox computed by the scriptThe MATLAB version of .matlab7rc.sh does not resetTOOLBOX.

The matlab script determines the path of the MATLAB root folder by looking up the folder tree from the_matlabroot_/bin folder (where thematlab script is located). MATLAB use the MATLAB variable to locate all files within the MATLAB folder tree.

You can change the definition of MATLAB. For example, you might change the definition:

Version History

expand all

If you start MATLAB using the matlab function with the -nojvm startup option, desktop tools and graphics appear as expected. In previous releases, desktop tools and graphics were not supported when MATLAB was started using the -nojvm startup option.

To prevent desktop tools and graphics from appearing, use the -nodisplay or -nodesktop options. For example:

The matlab command -nosplash startup option is no longer supported. If you specify the -nosplash option at startup, MATLAB ignores the option. Previously, you could use the -nosplash startup option to suppress the display of the splash screen.

If you use the -batch option and run code that creates dialog boxes that require user input, MATLAB throws an error. The exception is if you create the dialog box in a test created using the app testing framework, such as matlab.uitest.TestCase.chooseDialog, in which case the code runs without an error.

To start MATLAB non-interactively, use the -batch option. To start MATLAB interactively, use the -r option.