matlab (macOS)
Start MATLAB program from macOS Terminal
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/
,
where matlabroot
/MATLAB_release
.app/binmatlabroot
is the name of the folder in which you installed
MATLAB and release
is the MATLAB release number.
The matlab
script:
Determines the MATLAB root folder, the value returned by the
matlabroot
functionProcesses command-line options, if any
Reads the MATLAB startup file,
.matlab7rc.sh
Sets MATLAB environment variables
matlab
starts MATLAB with the specified startup options.option1 ... optionN
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.
Input Arguments
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 To run in batch processing mode, use the
If you use the
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 |
-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 |
---|---|
| Set the MATLAB folder to Example: |
| 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= | Start the version of MATLAB in the
|
Debugging Options
Option | Result |
---|---|
| Copy Command Window output, including error reports, into
Example:
|
-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 |
| Start MATLAB in debug mode. This option uses the debugger program name,
Debugger program command-line options,
Do not add a space between
D and Example:
|
| Enable use of the Java debugger. The Java debugger uses the default The port number is optional. However, to use the Java debugger while running multiple MATLAB sessions, you must specify a port number. The
|
Execute MATLAB Script or Function
Option | Result |
---|---|
| Execute MATLAB script, statement, or function non-interactively. MATLAB:
Use the
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 Example: |
| Execute the MATLAB
Note To set the initial working folder, use the
Example: Example: |
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
Option | Result |
---|---|
-nouserjavapath | Disable use of |
Specify License File
Option | Result |
---|---|
| Use the specified license file, |
Help Options
Option | Result |
---|---|
-h | Display startup options without starting MATLAB. |
-help | Same as |
Examples
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.
./matlab -nodisplay
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 -nodisplay
matlab -r "disp(['Current folder: ' pwd])"
More About
The .matlab7rc.sh
shell script contains variable
definitions used by the matlab
script. To redefine variables defined in the
matlab
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:
Current folder
Home folder
($HOME)
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.
| Definition and Standard Assignment Behavior |
---|---|
| Machine architecture MATLAB checks these values in this order:
|
| Final Load library path The final value is normally a colon-separated list of four sublists, each of which could be empty. The sublists are:
|
| MATLAB root folder |
| MATLAB search path The final value is a colon-separated list with the
|
| Shell to use with MATLAB “ This value is taken from the environment, unless
The
default |
| Shell to use instead of MATLAB checks for Use an
absolute path for the value of The default
|
| Path of the toolbox folder
The MATLAB version of |
The matlab
script determines the path of the MATLAB root folder by looking up the folder tree from the
matlabroot
/bin
folder (where the
matlab
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:
To run a different version of MATLAB
When your system uses certain types of automounting schemes and the path determined by the
matlab
script is not correct
Version History
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:
matlab -nojvm -nodisplay
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.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)