matlab (Windows) - Start MATLAB program from Windows system prompt - MATLAB (original) (raw)
Start MATLAB program from Windows system prompt
Syntax
Description
matlab
starts the MATLAB® program from the Microsoft® Windows® system prompt. In this topic the term matlab
refers to the command you type, and MATLAB refers to the program.
The matlab
command:
- Determines the MATLAB root folder, the value returned by the
matlabroot
function. - Processes command-line options and passes other options to MATLAB.
To capture the exit code, start MATLAB with the -wait
option.
matlab `option1 ... optionN`
starts MATLAB with the specified startup options.
Input Arguments
One or more startup options, specified as strings corresponding to valid startup options from the following tables.
Mode Options
Option | Result |
---|---|
-nojvm | Start MATLAB without allowing the JVM® software to be loaded in the session. Features that require Java® software are not supported. |
Display Options
Option | Result |
---|---|
-noFigureWindows | Disable the display of figure windows in MATLAB. |
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. |
Debugging Options
Option | Result |
---|---|
-logfile_filename_ | Copy Command Window output, including error log reports, in to filename, specified as a string.Example:-logfile output.log |
-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 provide 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 optionDisables changes to settingsDisables toolbox cachingLogs text to stdout andstderrExits 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 thebatchStartupOptionUsed 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
COM Server Options
Option | Result |
---|---|
-automation | Start MATLAB as a Component Object Model (COM) Automation server. MATLAB does not display the splash screen and minimizes the window. Use for a single call to MATLAB. |
-regserver | Register MATLAB as a COM server in the Windows registry.You must have administrator privileges to change the Windows registry. Based on your User Account Control (UAC) settings, you might need to right-click a Windows Command Prompt and select . If that option is not available, contact your system administrator.Alternatively, you can register MATLAB from the MATLAB command prompt. Type:regmatlabserverFor more information, see Register MATLAB as COM Server andregmatlabserver. |
-unregserver | Remove MATLAB COM server entries from the registry. |
Wait for MATLAB to Terminate
By default, when you call the matlab
command from a script, the command starts MATLAB and then immediately executes the next statements in the script. The -wait
option pauses the script until MATLAB terminates.
Option | Result |
---|---|
-wait | Use in a script to process the results from MATLAB. Calling MATLAB with this option blocks the script from continuing until the results are generated. |
Specify License File
For more information, see Update or Modify Network License Files.
Option | Result |
---|---|
-c_license_ | Use the License File,license, specified as a string, a semicolon-separated list of license file names, or a port@host entry. If specifying multiple files, separate the names by semicolons and enclose the entire list in quotation marks. If the path to your license file contains a space, enclose the path name in quotation marks.Example:-c license.lic |
Help Options
Option | Result |
---|---|
-h | Display options without starting MATLAB. |
-help | Same as -h option. |
-? | Same as -h option. |
Examples
matlab -logfile output.log
To return an exit status on the command line, start MATLAB with the -wait
option.
From the operating system prompt, type:
Tips
- To add folders to the MATLAB search path at startup, set the
MATLABPATH
environment variable before running thematlab
command. For more information, see Add Folders to the MATLAB Search Path at Startup.
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:
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 asmatlab.uitest.TestCase.chooseDialog
, in which case the code runs without an error.
If you specify any of the following OpenGL® startup options, MATLAB issues a warning and the option has no effect.
-softwareopengl
-nosoftwareopengl
-softwareopenglmesa
-noopengl
This change was announced in R2022a.
To start MATLAB non-interactively, use the -batch
option. To start MATLAB interactively, use the -r
option.