MATLAB Programming

MATLAB Programming MATLAB Programming

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
23.06.2015 Views

6 Data Import and Export Importing from a File TostarttheWizardanduseafilebrowsertolocatethefiletoimport,useone of the menu options or MATLAB commands shown here: • Select Import Data from the File menu • Type uiimport -file • Type uiimport, andthenclickBrowse If you already know the name of the file to import, use one of the following means to initiate the operation: • In the Current Directory browser, right-click the filename and select Import Data • Type uiimport filename, wherefilename is an unquoted string containing the name of the file to import. Importing from the Clipboard To import from the system clipboard, use one of the menu options or MATLAB commands shown here: • Select Paste to Workspace from the Edit menu • Type uiimport -pastespecial • Type uiimport, andthenclickClipboard Importing to a Structure Specifying an output argument with the uiimport command tells MATLAB to return the imported data in the fields of a single structure rather than as separate variables. The command S = uiimport('filename') imports the file filename to the fields of structure S. Thefilename argument is a single-quoted string containing the name of the file to import. 6-10

Using the Import Wizard If you are importing from a binary file, skip ahead to step 4: Determine Assignment to Variables. Previewing Contents of the File or Clipboard [Text only] When the Import Wizard imports text data from a file or the clipboard, it opens the dialog box shown here and displays a portion of the raw data in the preview pane on the left. You can use this display to verify that the file contains the data you expect. Preview of the data in the file. Delimiter found in file. Number of lines of header text ignored. Check this box to generate an M-file function to perform future imports of this type. The pane on the right side of the dialog box shows how MATLAB has assigned the imported data to a default set of variables. The variable names appear in the tabs above the display pane. Click any of these tabs to see the values assigned to that variable. The variable names are derived from categories into which the Import Wizard has sorted the data. These are 6-11

6 Data Import and Export<br />

Importing from a File<br />

TostarttheWizardanduseafilebrowsertolocatethefiletoimport,useone<br />

of the menu options or <strong>MATLAB</strong> commands shown here:<br />

• Select Import Data from the File menu<br />

• Type uiimport -file<br />

• Type uiimport, andthenclickBrowse<br />

If you already know the name of the file to import, use one of the following<br />

means to initiate the operation:<br />

• In the Current Directory browser, right-click the filename and select<br />

Import Data<br />

• Type uiimport filename, wherefilename is an unquoted string<br />

containing the name of the file to import.<br />

Importing from the Clipboard<br />

To import from the system clipboard, use one of the menu options or <strong>MATLAB</strong><br />

commands shown here:<br />

• Select Paste to Workspace from the Edit menu<br />

• Type uiimport -pastespecial<br />

• Type uiimport, andthenclickClipboard<br />

Importing to a Structure<br />

Specifying an output argument with the uiimport command tells <strong>MATLAB</strong><br />

to return the imported data in the fields of a single structure rather than<br />

as separate variables.<br />

The command<br />

S = uiimport('filename')<br />

imports the file filename to the fields of structure S. Thefilename argument<br />

is a single-quoted string containing the name of the file to import.<br />

6-10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!