Main Content

MLStartDir

Specify MATLAB current working folder after startup

Description

example

= MLStartDir(path) sets the MATLAB® current working folder after MATLAB startup. Use this syntax when working directly in a worksheet.

example

MLStartDir path sets the MATLAB current working folder. Use this syntax in a VBA macro.

out = MLStartDir(path) lets you find errors when you execute the MLStartDir function in a VBA macro. If the MLStartDir function fails, then out is a string containing an error code. Otherwise, out is 0.

Examples

collapse all

Set the current working folder in a spreadsheet.

Open Excel® and make sure cell A1 is selected in the worksheet. To set the MATLAB current working folder to d:\work after startup, enter this text in the cell and press Enter:

= MLStartDir("d:\work")

The MLStartDir function sets the current working folder.

Set the current working folder in a VBA macro. The folder name contains a space.

On the Developer tab in Excel, click Visual Basic in the Code group. The Visual Basic® Editor window opens.

From the Insert menu, select Module to insert a new module. Embed the folder path in single quotes within double quotes. Set the MATLAB current working folder to d:\my work. In the Module1 window, enter this VBA code containing a macro named StartDir.

Sub StartDir()
    MLStartDir "'d:\my work'"
End Sub

The StartDir macro uses the MLStartDir function to set the current working folder. For details about working with modules, see Excel Help.

Run the macro by clicking the Run Sub/UserForm button on the VBA toolbar. For details about running macros, see Excel Help.

The MLStartDir function sets the current working folder.

Input Arguments

collapse all

MATLAB current working folder path, specified as a string. The string indicates the path to the new working folder after MATLAB starts.

Example: "d:\work"

Tips

  • This function does not work like the standard Microsoft® Windows® Start In setting because it does not automatically run startup.m or matlabrc.m in the specified folder.

  • The working folder changes only if you run MATLAB after you run this function. Running this function while MATLAB is running does not change the working folder for the current session. In this case, MATLAB uses the specified folder as the working folder when it is restarted.

  • To work with VBA code in Excel with Spreadsheet Link™, you must enable Spreadsheet Link as a reference in the Microsoft Visual Basic Editor. For details, see Installation.

Version History

Introduced in R2006b