MATLAB:Files

From PrattWiki
Jump to navigation Jump to search

CSV Files

CSV or "comma separated values" files are very common. For MATLAB to read them, they must contain only numerical data. If they also have text, you will either need to convert them to an XLS file or write a script that uses textscan to get the information.

XLS and XLSX Files

MATLAB can import information from Excel files using the xlsread command. The xlsread command has three different outputs:

  • The first will be an array of the numerical values stored in the spreadsheet. If an entry is empty or non-numerical, the matrix will contain NaN in those locations. Furthermre, if there is an entire row or column of non-numerical data, it will be skipped.
  • The second output is a cell array of the text information. If an entry is empty or if it contains numerical information that can be put in the first output, the cell will be an empty string.
  • The final output is a cell array of the raw data. If an entry is empty, this array will contain NaN in that location.