askvity

How to create folders in MATLAB?

Published in MATLAB file management 3 mins read

Creating folders in MATLAB is a straightforward process that can be done either through the graphical user interface (GUI) or using command-line functions.

You can create new folders directly within the MATLAB interface or by using the mkdir command in the Command Window.

Using the Current Folder Browser

One of the simplest ways to create a folder is by using MATLAB's built-in file browser.

  • Right-click in white space within the Current Folder browser pane.
  • From the context menu that appears, select New > Folder.
  • MATLAB immediately creates a new folder named New Folder in the current directory and automatically selects it, allowing you to rename it right away.

This method is ideal for interactive file management within the MATLAB environment.

Using the mkdir Command

For scripting, automation, or when working in the Command Window, the mkdir function is the standard way to create folders.

The basic syntax is:

mkdir folderName

Where folderName is the name you want to give the new folder.

Examples:

  • To create a folder named my_project_data in the current working directory:

    mkdir my_project_data
  • To create a folder within an existing subfolder (e.g., create results inside my_project_data):

    mkdir my_project_data/results

    Note: MATLAB automatically creates parent folders if they don't exist when using this syntax (e.g., if my_project_data didn't exist, it would be created first, then results inside it). This is very useful for setting up project structures.

  • You can also specify a full path to create a folder in a location outside the current directory:

    mkdir C:\Users\YourName\Documents\MATLAB\new_folder_location

    Remember to use appropriate file separators for your operating system (\ for Windows, / for macOS/Linux).

The mkdir function is powerful for organizing your MATLAB code and data programmatically.

Summary Table

Method Description Use Case
Current Folder GUI Right-click in white space in the Current Folder browser, select New > Folder. Creates New Folder. Interactive file management
mkdir command Use the mkdir('folderName') function in the Command Window or a script. Can specify relative or full paths. Scripting, automation, Command Line

Both methods effectively allow you to create new directories for organizing your MATLAB files and projects.

Related Articles