Programming Previous page   Next Page

Working with Spreadsheets

You can use MATLAB to import and export data to the following types of spreadsheets:

Microsoft Excel Spreadsheets

This section covers

See the xlsfinfo, xlswrite, and xlsread reference pages for more detailed information and examples.

Getting Information About the File

Use the xlsfinfo function to determine if a file contains a readable Microsoft Excel spreadsheet.

Inputs to xlsfinfo are

Outputs from xlsfinfo are

Example -- Querying an XLS File.   This example returns information about spreadsheet file tempdata.xls:

Exporting to the File

Use the xlswrite function to export a matrix to an Excel spreadsheet file. With xlswrite, you can export data from the workspace to any worksheet in the file, and to any location within that worksheet.

Inputs to xlswrite are

Outputs from xlswrite are

Example -- Writing To an XLS File.   This example writes a mix of text and numeric data to the file tempdata.xls. Call xlswrite, specifying a worksheet labeled Temperatures, and the region within the worksheet to write the data to. The 4-by-2 matrix is written to the rectangular region that starts at cell E1 in its upper-left corner:

Adding a New Worksheet.   If the worksheet being written to does not already exist in the file, MATLAB displays the following warning:

You can disable these warnings with the command

Importing from the File

Use xlsread to import a matrix from an Excel spreadsheet file into the MATLAB workspace. You can import data from any worksheet in the file, and from any location within that worksheet. You can also optionally have xlsread open an Excel window showing the file and then interactively select the worksheet and range of data to be read by the function.

Inputs to xlsread are

Three separate outputs from xlsread are

Example -- Reading from an XLS File.   Continuing with the previous example, to import only the numeric data, use xlsread with a single return argument. xlsread ignores any leading row or column of text in the numeric result:

To import both numeric data and text data, specify two return values for xlsread:


Previous page  Exporting Audio/Video Data Lotus 123 Spreadsheets Next page

© 1994-2005 The MathWorks, Inc.