Main Content

matlab (Windows)

StartMATLABprogram fromWindowssystem prompt

Description

matlabstarts the MATLAB®program from the Microsoft®Windows®system prompt. In this topic the termmatlabrefers to the command you type, and MATLAB refers to the program.

Thematlabcommand:

  • Determines the MATLAB root folder, the value returned by thematlabrootfunction.

  • Processes command-line options and passes other options to MATLAB.

To capture the exit code, start MATLAB with the-waitoption.

example

matlaboption1 ... optionNstarts MATLAB with the specified startup options.

Input Arguments

expand all

一个或多个启动选项, specified as strings corresponding to valid startup options from the following tables.

Display Options

Option Result
-noFigureWindows

Disable the display of figure windows in MATLAB.

-nosplash

Do not display the splash screen during startup.

Set Initial Working Folder

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

Option Result

-sdfolder

Set the MATLAB folder tofolder, specified as a string.

Example:matlab -sd "C:\work"

-useStartupFolderPref

Set the MATLAB folder to the value specified by theInitial working folderoption in theGeneral Preferences面板。

Debugging Options

Option Result

-logfilefilename

Copy Command Window output, including error log reports, in tofilename, specified as a string.

Example:-logfile output.log

-jdbportnumber

Enable use of the Java®debugger. The Java debugger uses the defaultportnumbervalue 4444 to communicate with MATLAB.

端口号是可选的。但仍r, to use the Java debugger while running multiple MATLAB sessions, you must provide a port number. Theportnumbervalue 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

-batchstatement

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

  • Starts without the desktop

  • Does not display the splash screen

  • Executesstatement

  • Disables changes to preferences

  • Disables toolbox caching

  • Logs text tostdoutandstderr

  • Does not display modal dialog boxes

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

statementis MATLAB code enclosed in double quotation marks. Ifstatementis 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-batchoption in non-interactive scripting or command line work flows. Do not use this option with the-roption.

To test if a session of MATLAB is running in batch mode, call thebatchStartupOptionUsedfunction.

Example:-batch "myscript"

-rstatement

Execute the MATLABstatement. Use this option for interactive work flows. Do not use this option with the-batchoption.

Note

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

-sdfolder

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.

Disable Searching Custom Java Class Path

Option Result
-nouserjavapath

Disable use ofjavaclasspath.txtandjavalibrarypath.txtfiles. For more information, seeSpecifying Java Startup Options.

OpenGLLibrary Options

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

Option Result
-softwareopengl

Force MATLAB to start with software OpenGL libraries.

-nosoftwareopengl

Disable auto-selection of OpenGL software.

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 selectRun as administrator. If that option is not available, contact your system administrator.

Alternatively, you can register MATLAB from the MATLAB command prompt. Type:

regmatlabserver

For more information, seeRegister MATLAB as COM Serverandregmatlabserver.

-unregserver

Remove MATLAB COM server entries from the registry.

Wait forMATLABto Terminate

By default, when you call thematlabcommand from a script, the command starts MATLAB and then immediately executes the next statements in the script. The-waitoption 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, seeNetwork License Files.

Option Result

-clicense

Use the License File,license, specified as a string, a semicolon-separated list of license file names, or aport@hostentry. 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 "c:\TMW license\license_agreement.txt"

Help Options

Option Result
-h

Display options without starting MATLAB.

-help

Same as-hoption.

-?

Same as-hoption.

Examples

expand all

matlab -nosplash
matlab -logfile output.log

To return an exit status on the command line, start MATLAB with the-waitoption.

From the operating system prompt, type:

matlab -wait

Tips

Compatibility Considerations

expand all

Not recommended starting in R2019a