Programming Previous page   Next Page

Using the Import Wizard

The easiest way to import data into MATLAB is to use the Import Wizard. You do not need to know the format of the data to use this tool. You simply specify the file that contains the data and the Import Wizard processes the file contents automatically.

This section discusses how to import these types of data using the wizard:

You can also use the Import Wizard to import HDF data. See Using the HDF Import Tool for more information.

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. 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. In many cases, the Import Wizard determines the delimiter automatically. However, you might need to specify the character used in your text file. For more information, see Specifying the Delimiter. 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. For more information, see Selecting the Variables to Import.
  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 space character as the delimiter used in the file and has created three tabs 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 vector 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 vector for each student that contains that student's grades. To create these variables, click the Create vectors from each row using row names button. When you click this option, the Import Wizard reprocesses the file, creating these new vectors.

.

When you are satisfied with the list of vectors to be imported, click Finish to bring the data into the MATLAB workspace. This button also dismisses the Import Wizard. The MATLAB workspace now contains the vectors.


Previous page  Text Data Using the Import Wizard with Binary Data Next page

© 1994-2005 The MathWorks, Inc.