Table of Contents
Overview of the Import Tool
The Import Tool in MATLAB provides a graphical way to bring data from files into the workspace without writing code. It is especially useful for beginners because it lets you preview the file, choose what to import, and see how MATLAB will interpret the data before you actually load it. The Import Tool can handle many common text and spreadsheet formats, such as .txt, .csv, and Excel files.
You do not use the Import Tool from the Command Window directly. Instead, you open a file in a way that launches the Import Tool interface, then interact with that interface to configure the import. At the end, MATLAB generates variables for you and can optionally create reusable code that performs the same import steps.
Opening Files with the Import Tool
There are several common ways to start the Import Tool. The most typical approach is through the Current Folder browser. When you see your data file in the Current Folder panel, you can double click it if MATLAB recognizes it as an importable file type. For supported file types this opens the Import Tool window rather than a text editor or other viewer.
Another way is to right click a file in the Current Folder and choose the menu entry that refers to importing data. This is often labeled in a way that indicates importing or opening with the Import Tool. This method is useful if double clicking would otherwise open the file in a different application.
You can also start the Import Tool from the toolstrip. When you select a file in the Current Folder, certain tabs in the MATLAB desktop, such as the Home tab, may show an Import Data button. Clicking that button with a suitable file selected will launch the Import Tool for that file.
Understanding the Import Tool Interface
Once the Import Tool opens, it displays a preview of the data in a table-like view. This preview shows rows and columns as MATLAB currently interprets them, not yet as variables in the workspace. Above or beside the preview you will see controls that let you adjust how the file is parsed. Although the exact layout can change between MATLAB versions, you will always have access to options such as delimiters, header lines, and output names.
The preview table often uses different formatting to indicate how MATLAB is treating each column. Numeric columns may appear right aligned, while text columns may appear left aligned. If MATLAB detects missing or nonnumeric entries in a numeric column, these may be highlighted or marked so that you can adjust the import settings.
Each prospective output variable has a proposed name that appears above its column or in a side panel. MATLAB uses information such as the first row of the file or default naming rules to suggest these names. You can change these names before importing to avoid later renaming in the workspace.
Choosing Delimiters and File Structure
Many text files separate columns using characters such as commas, tabs, or semicolons. The Import Tool lets you pick which delimiter applies. A dropdown menu typically lists common delimiters, for example comma, tab, or space. When you change this setting, the preview updates to show how MATLAB will slice the text into columns.
If your file uses an uncommon delimiter, for example a vertical bar character, you can usually select a custom delimiter option and type the character. Watching the preview is important here because it lets you confirm that the file lines split into sensible columns. If the preview shows all data in one column, or too many empty columns, your delimiter setting probably needs adjustment.
Some files also contain text qualifiers, such as double quotes around entries that might contain delimiters inside the text. The Import Tool often includes an option to specify these quotation characters so that commas inside quoted text are not treated as column separators. Again, the preview is your guide to correct configuration.
Handling Headers and Variable Names
Many data files begin with one or more header lines that contain descriptions or metadata rather than data. The Import Tool usually offers settings called something like "Number of header lines" or similar that allow you to skip a certain number of initial rows. As you change this number, the preview will adjust. The goal is to have the first visible row correspond to actual data, not descriptive text.
For files that include column names in the first data-like row, the Import Tool can often treat that row as variable or column names. There is typically a checkbox or selection that controls whether the first row is used as headers or interpreted as data. When the Import Tool uses that row for variable names, it removes it from the data portion and converts the text into MATLAB friendly names by removing spaces or special characters. For instance, a column labeled "Total Sales ($)" might become TotalSales.
The Import Tool also provides a way to edit these names directly. You can click on the proposed name and change it. It is good practice to choose short, descriptive names that follow MATLAB naming rules, so avoid spaces and leading numbers.
Selecting Columns and Data Types
You do not have to import every column from a file. In the Import Tool preview, you can usually select or deselect individual columns. This is often done with checkboxes near the column headers or through a menu. Deselecting a column means that MATLAB will ignore that column during the import, which keeps your workspace cleaner and may speed up operations on large files.
Each column is assigned a data type based on how MATLAB interprets its contents. Common types include numeric arrays, text (character or string arrays), categorical data, and sometimes date and time types. In the Import Tool, you can click on a column header to change its type manually. For example, you might convert a coded text column to a categorical array or a text date column to a datetime array, if these options are presented.
If MATLAB misinterprets a column, for instance by treating numeric looking data as text because of an unusual character, you can try changing the data type in the Import Tool instead of fixing the file externally. When you change the type, the preview will show how MATLAB converts the data, including any problematic entries that become missing values.
Specifying How to Import the Output
The Import Tool can create different kinds of variables based on how you want to work with the data. For some file formats and settings, you can choose to import the entire dataset into a table variable. In that case, each column becomes a variable inside the table, and the table itself appears as one variable in the Workspace. Alternatively, you may choose to create a separate variable in the workspace for each column.
These choices often appear in a section of the Import Tool interface that describes how to output the data. For example, you might have a setting like "Output type: table" or "Output type: numeric matrix," and the preview explains what each choice does. Tables are usually more convenient when you have mixed data types in different columns, while numeric matrices are more appropriate when all columns are numeric.
You can usually specify the name of the main output variable, for example data, T, or any other valid MATLAB name. If you choose to create multiple variables, the names for those variables are determined by the column names or by default naming rules, and you can edit them before confirming the import.
Importing Part of the Data
Sometimes you only need a subset of the file, for example the first few hundred rows or a specific block of columns. The Import Tool often provides controls to limit the imported range. This could be a way to specify starting and ending rows, or to select a rectangular region directly in the preview by dragging your mouse.
If you select a subset of rows, MATLAB imports only that portion of the file into the workspace. This can be useful for testing or for working with large files that would otherwise consume too much memory. When importing from spreadsheets such as Excel, you may also be able to pick a specific sheet and cell range.
Selecting subsets in the Import Tool affects both what appears in the preview and what will be created as variables when you finalize. It does not alter the original file on disk, only what MATLAB reads from it.
Finishing the Import and Creating Variables
After you configure all the import settings, you confirm the operation so that MATLAB reads the file and creates variables in the workspace. This is usually done with a button such as "Import Selection" or similar. Once you click it, the Import Tool reads the data using the settings you have chosen and places the resulting variables in the Workspace panel, where you can use them like any other variables.
If you imported a table, you might see a new variable such as T in the Workspace. If you imported separate columns, you will see one variable per column. You can then inspect their size and content with regular MATLAB commands or by opening them in the Variable Editor.
The Import Tool session itself can usually be closed once you are satisfied with the result. The variables remain in the workspace as long as your MATLAB session is active or until you clear them or close MATLAB without saving.
Generating Reusable Import Code
One powerful feature of the Import Tool is its ability to generate MATLAB code that reproduces the import steps you have configured through the graphical interface. After you finish adjusting the import options, you can often choose a menu item or button that produces MATLAB code. This code typically appears in the Editor as a new script or function.
The generated code includes commands that read the file, apply delimiters and header options, assign variable names and types, and create the same output variables you would get by clicking the import button. It may use high level functions like readtable, readmatrix, or other file reading functions with options that match your choices.
You can save this generated script or function and run it later instead of reopening the Import Tool for the same type of file. This is particularly helpful for repeated imports of similar data, for example a daily log file with the same structure. You may adjust the filename in the code while keeping all other settings unchanged.
Common Issues and How the Import Tool Helps
When data files contain irregular formatting, blank lines, or inconsistent columns, imports can fail or produce unexpected results. The Import Tool helps by letting you see these problems in the preview. Unexpected empty columns, misaligned rows, or highlighted problematic entries are clues that you might need to adjust delimiters, header lines, or data types.
Another common situation is the presence of missing values, sometimes represented by placeholders such as "NA" or other text. The Import Tool often allows you to specify how to treat certain text as missing. When you configure these rules, the preview shows which values become missing in MATLAB, and this affects the variables you create.
If the tool cannot interpret some values as numeric or dates, those entries may appear as missing or as text. You can use the type selection options to experiment with how MATLAB handles those columns. For very complex or inconsistent files, the Import Tool might not be able to handle every case cleanly, but it still provides a useful view of what is inside the file so that you can decide on further steps or preprocessing.
Key points to remember:
The Import Tool provides a graphical interface to preview and configure data imports before they create variables in the workspace.
You can adjust delimiters, header lines, column names, selected columns, and data types, and you should watch the preview to confirm that MATLAB interprets the file correctly.
You can choose different output forms, such as a single table variable or multiple separate variables, and you can restrict the import to a subset of rows or columns.
The Import Tool can generate MATLAB code that reproduces your import settings, which is useful for repeating the same import process without manual steps.