Often it is convenient to take data from an Excel spreadsheet to
further manipulate the data or graph the data in Excel. This is
easy to do using the "xlsread" function.
There are three related forms of the "xlsread" function:
Version 1 |
|
Syntax |
A = xlsread('filename') |
Explanation |
A = xlsread('filename') returns numeric data in array A from
the first sheet in Microsoft Excel spreadsheet file named filename.
xlsread ignores leading rows or columns of text. However, if
a cell not in a leading row or column is empty or contains text,
xlsread puts a NaN in its place in A. (NaN is the MATLAB symbol
for "not a number"). |
Example |
The Microsoft Excel spreadsheet file, testdata1.xls, contains
this data:
1 6
2 7
3 8
4 9
5 10
To read this data into MATLAB, use this command: A = xlsread('testdata1.xls')
A =
1 6
2 7
3 8
4 9
5 10
|
Version 2 |
|
Syntax |
[A, B ] = xlsread('filename') |
Explanation |
[A, B]= xlsread('filename') returns numeric data in array
A, text data in cell array B. If the spreadsheet contains
leading rows or columns of text, xlsread returns only those
cells in B. If the spreadsheet contains text that is not in
a row or column header, xlsread returns a cell array the same
size as the original spreadsheet with text strings in the
cells that correspond to text in the original spreadsheet.
All cells that correspond to numeric data are empty.
|
Example |
The Microsoft Excel spreadsheet file, tempdata.xls, contains
two columns of numeric data with text headers for each column:
Time Temp
12 98
13 99
14 97
If you want to import only the numeric data, use xlsread with
a single return argument. xlsread ignores a leading row or column
of text in the numeric result.
[ndata, headertext] = xlsread('tempdata.xls')
ndata =
12 98
13 99
14 97
headertext =
'time' 'temp' |
Version 3 |
|
Syntax |
[A,B] = xlsread('filename','sheetname') |
Explanation |
[A,B]= xlsread('filename','sheetname') read sheet specified
in sheetname. Returns an error if sheetname does not exist.
To determine the names of the sheets in a spreadsheet file,
use xlsfinfo. |
Example |
(no example provided) |
|