This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Read Spreadsheet Data into Arrays

Import mixed numeric and text data into separate arrays in MATLAB®, using the xlsread function.

Preview Data

This example uses the sample spreadsheet file climate.xlsx that contains a worksheet named Temperatures. Load the file and preview its contents in a spreadsheets application like Excel®. The screenshot here shows that this file contains column-oriented tabular data.

Read All Numeric Data into Matrix

Import only the numeric data into a matrix, using xlsread with a single output argument. The xlsread function ignores any leading row or column of text in the numeric result.

num = xlsread('climate.xlsx','Temperatures')
num = 

    12    98
    13    99
    14    97

Read Both Numeric and Text Data into Arrays

Alternatively, import both numeric data and text data by specifying two output arguments. The xlsread function returns the numeric data in the array and the text data in the cell array.

[num,txt] = xlsread('climate.xlsx','Temperatures')
num = 

    12    98
    13    99
    14    97

txt = 4x3 cell array
    {'Time'  }    {'Temp'  }    {'Visibility'   }
    {0x0 char}    {0x0 char}    {'clear'        }
    {0x0 char}    {0x0 char}    {'clear'        }
    {0x0 char}    {0x0 char}    {'partly cloudy'}

Read Specified Range into Matrix

Read only the first row of data by specifying a range, 'A2:B2'.

first_row = xlsread('climate.xlsx','Temperatures','A2:B2')
first_row = 

    12    98

See Also

| |

Related Topics

Was this topic helpful?