Académique Documents
Professionnel Documents
Culture Documents
http://in.mathworks.com/help/matlab/ref/xlsread....
xlsread
Read Microsoft Excel spreadsheet file
Syntax
num = xlsread(filename)
example
num = xlsread(filename,sheet)
num = xlsread(filename,xlRange)
example
num = xlsread(filename,sheet,xlRange)
example
num = xlsread(filename,sheet,xlRange,'basic')
[num,txt,raw] = xlsread( ___ )
example
___
= xlsread(filename,-1)
[num,txt,raw,custom] = xlsread(filename,sheet,xlRange,'',functionHandle)
example
Description
example
num = xlsread(filename) reads data from the first worksheet in the Microsoft Excel
spreadsheet file named filename and returns the numeric data in array num.
On Windows systems with Microsoft Excel software, xlsread reads any file format recognized
by your version of Excel.
If your system does not have Excel for Windows, xlsread operates in basic import mode, and
reads only XLS, XLSX, XLSM, XLTX, and XLTM files.
num = xlsread(filename,sheet) reads the specified worksheet.
example
num = xlsread(filename,xlRange) reads data from the specified range, xlRange, of the first
mode, the default on systems without Excel for Windows. If you do not specify all the arguments,
use empty strings as placeholders, for example, num = xlsread(filename,'','','basic').
example
1 of 6
[num,txt,raw] = xlsread( ___ ) additionally returns the text fields in cell array txt, and the
unprocessed data (numbers and text) in cell array raw using any of the input arguments in the
previous syntaxes. If xlRange is specified, leading blank rows and columns in the worksheet that
precede rows and columns with data are returned in raw.
Monday 24 November 2014 06:53 PM
function does not change the data stored in the spreadsheet. This syntax is supported only on
Windows systems with Excel software.
Examples
collapse all
Read Data from First Worksheet Into Numeric Array
Create an Excel file named myExample.xlsx.
First
1
4
7
Second
2
5
8
Third
3
x
9
filename = 'myExample.xlsx';
A = xlsread(filename)
A =
1
4
7
2
5
8
3
NaN
9
2 of 6
filename = 'myExample.xlsx';
sheet = 1;
http://in.mathworks.com/help/matlab/ref/xlsread....
xlRange = 'B2:C3';
subsetA = xlsread(filename, sheet, xlRange)
subsetA =
2
3
5
NaN
filename = 'myExample.xlsx';
columnB = xlsread(filename,'B:B')
columnB =
2
5
8
For better performance, specify the row numbers in the range, as shown in the previous example.
3 of 6
2
5
8
3
NaN
9
text =
'First'
''
''
'Second'
''
''
'Third'
''
'x'
alldata =
'First'
[
1]
[
4]
[
7]
'Second'
[
2]
[
5]
[
8]
'Third'
[
3]
'x'
[
9]
misc = pi*gallery('normaldata',[10,3],1);
xlswrite('myExample.xlsx',misc,'MyData');
Worksheet MyData contains the following values, which range from -6.6493 to 3.4845:
2.7156
0.2959
-2.6764
2.7442
-1.3761
-1.3498
-3.4643
1.2448
-3.0314
0.5292
-6.1744
-2.3383
-1.7351
-2.5752
3.4845
-1.9319
-0.8000
-0.8477
-5.2527
-5.8938
1.8064
-2.7210
-6.6493
-3.0300
0.6683
1.5014
0.3162
0.9344
1.7912
-5.1035
Read the data from the worksheet, and reset any values outside the range [-3, 3]. Specify the sheet name,
but use '' as placeholders for the xlRange and 'basic' inputs.
4 of 6
trim = xlsread('myExample.xlsx','MyData','','',@setMinMax)
Monday 24 November 2014 06:53 PM
trim =
2.7156
0.2959
-2.6764
2.7442
-1.3761
-1.3498
-3.0000
1.2448
-3.0000
0.5292
-3.0000
-2.3383
-1.7351
-2.5752
3.0000
-1.9319
-0.8000
-0.8477
-3.0000
-3.0000
http://in.mathworks.com/help/matlab/ref/xlsread....
1.8064
-2.7210
-3.0000
-3.0000
0.6683
1.5014
0.3162
0.9344
1.7912
-3.0000
[trim,txt,raw,idx] = xlsread('myExample.xlsx',...
'MyData','','',@setMinMax);
disp(idx)
7
5 of 6
11
15
19
20
23
24
30
Monday 24 November 2014 06:53 PM
Input Arguments
expand
all
filename
http://in.mathworks.com/help/matlab/ref/xlsread....
string
Worksheet to read
string | positive integer
sheet
xlRange
string
Flag to request reading in basic mode
literal string
'basic'
functionHandle
function handle
OutputallArguments
expand
Numeric data
matrix
num
Text data
cell array
txt
Unprocessed data
cell array
raw
Limitations
xlsread reads only 7-bit ASCII characters.
xlsread does not support non-contiguous ranges.
More
expand About
all
Algorithms
Import and Export Dates to Excel Files
See Also
function_handle | importdata | readtable | uiimport | xlsfinfo | xlswrite
6 of 6