Development Environment    

Using the Import Wizard with Text Data 

To import text data using the Import Wizard, perform these steps:

  1. Start the Import Wizard, by selecting the Import Data option on the MATLAB File menu. MATLAB displays a file selection dialog box. You can also use the uiimport function to start the Import Wizard.
  1. To use the Import Wizard to import data from the clipboard, select the Paste Special option on the MATLAB Edit menu. You can also right-click in the MATLAB Command Window and choose Paste Special from the context menu. Skip to step 3 to continue importing from the clipboard.

  1. Specify the file you want to import in the file selection dialog box and click Open. The Import Wizard opens the file and attempts to process its contents.
  2. Specify the character used to separate the individual data items. This character is called the delimiter or column separator. The Import Wizard can determine the delimiter used in many cases. However, you might need to specify the character used in your text file. See Specifying the Delimiter for more information. Once the Import Wizard has correctly processed the data, click Next.
  3. Select the variables that you want to import. By default, the Import Wizard puts all the numeric data in one variable and all the text data in other variables, but you can choose other options. See Selecting the Variables to Import for more information.
  4. Click Finish to import the data into the workspace.

Specifying the Delimiter

When the Import Wizard opens a text file, or copies data from the clipboard, it displays a portion of the raw data in the preview pane of the dialog box. You can use this display to verify that the file contains the data you expected.

The Import Wizard also attempts to process the data, identifying the delimiter used in the data. The Import Wizard displays the variables it has created based on its interpretation of the delimiter, using tabbed panels to display multiple variables.

For example, in the following figure, the Import Wizard has opened this sample file, grades.txt.

In the figure, note how the Import Wizard has correctly identified the tab character as the delimiter used in the file and has created three variables from the data:

Handling Alphabetic Data.   The Import Wizard recognizes data files that use row or column headers and extracts these headers into separate variables. It can also ignore any text header lines that might precede the data in a file.

Specifying Other Delimiters.   If the Import Wizard cannot determine the delimiter used in the data, it displays a preview of the raw data, as before, but the variables it displays are not correct. If your data uses a character other than a comma, space, tab, or semicolon as a delimiter, you must specify it by clicking the Other button and entering the character in the text box. The Import Wizard immediately reprocesses the data, displaying the new variables it creates.

Selecting the Variables to Import

The Import Wizard displays a list of the variables it has created from your data. To select a variable to import, click in the check box next to its name. By default, all variables are selected.

The Import Wizard displays the contents of the variable that is highlighted in the list in the right pane of the dialog box. To view the contents of one of the other variables, click it. Choose the variables you want to import and click Next.

Changing the Variable Selection.   By default, the Import Wizard puts all the numeric data in the file into one variable. If the file contains text data, the Import Wizard puts it in a separate variable. If the file contains row or column headers, the Import Wizard puts them in separate variables, called rowheaders or colheaders, respectively.

In some cases, it might be more convenient to create a variable from each row or column of data and use the row header or column header text as the name of each variable. To do this, click the appropriate button from the list of buttons at the top of the dialog box.

For example, it eases calculation of the student averages if you create a separate variable for each student, which contains that student's grades. To create these variables, click the Create variables from each column using row names button. When you click this option, the Import Wizard reprocesses the file, creating these new variables.


When you are satisfied with the list of variables to be imported, click Next to bring the data into the MATLAB workspace. This button also dismisses the Import Wizard. The Import Wizard displays a message in the MATLAB Command Window, reporting that it created variables in the workspace. In the following example, note how the numeric text data in each variable is imported as an array of doubles.

  Importing Text Data Using Import Functions with Text Data