Skip to main content

9.7) Reading Spreadsheet Data


  • Matlab function "xlsread" is used to read Microsoft Excel spreadsheets
  • In Windows, "xlsread" is able to read any type of Excel spreadsheet. Under Unix/Linux and Mac OS, "xlsread" is only able to conduct a basic import. The main syntax is as follows:
  • [matlab]
    >> % reads the numeric data from the first worksheet of filename
    >> A=xlsread(filename)
    >> % specify the worksheet name to import numerical data from
    >> A=xlsread(filename, sheet)
    >> % reads the numerical data, the text data and
    >> % all the data into appropriately named arrays
    >> [ndata, text, alldata]=xlsread(filename)
    [/matlab]

  • For example, the file "dino_data.xlsx" contains site dinoflagelate data used as a palaeoceanographic proxy, data useful in understanding the climate of the geological past. The single worksheet can be loaded using:
  • [matlab]
    >> data=xlsread('dino_data.xlsx')
    [/matlab]
    Or
    [matlab]
    >> [ndata,text,alldata]=xlsread('dino_data.xlsx')
    [/matlab]

  • Alternatively we could have used "importdata" to load all of the data into a structure
  • [matlab]
    >> data=importdata('dino_data.xlsx')
    [/matlab]