File Exchange

image thumbnail


version (2.45 KB) by Matthew Kelly
converts a spreadsheet file to a Matlab struct

1 Download

Updated 13 Dec 2015

View License

% DATA = xls2mat(In_File_Name,Out_File_Name)
% Take an excel spreadsheet and convert it to a matlab struct,
% with a field for each column in the spreadsheet.
% This function xls2mat, assumes a special structure in the spreadsheet
% file, described in detail below.
% In_File_Name must be a .xls extension
% Out_File_Name must be a .mat extension
% DATA = a struct with one field for each column in the spreadsheet, and
% the name of the field will be the name of the column. If the data in
% the given column is strings, then the corresponding field will be a
% cell array. If it is numeric, then the field will be a column vector.
% If the second argument is present, then DATA will be written to a .mat
% file.
% This function assumes a special structure in the spreadsheet:
% 1) The first row is a header row of strings. These strings must be valid
% matlab variable names, and they must be unique (or they will be
% overwritten).
% 2) Each column has a consistent data type (numerical or string)
% 3) There must be no blank columns, or blanks in the first row of data
% This function is built around xlsread(), and thus will work on any files
% that are correctly recognized by xlsread(). Type
% >> help xlsread
% for additional details regarding this.

Cite As

Matthew Kelly (2019). xls2mat (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Excellent point. I did a few experiments and it looks like it works on new excel spreadsheets as well. In theory, xls2mat() should work on any file that xlsread() works on. I've updated the documentation to reflect this. Thanks!

What is an "old format excel spreadsheet"? How do I know if I have an "old" format spreadsheet? Surely a slightly more precise version reference would be preferable to using the adjective "old".


1) Cleaned up documentation.
2) Added functionality - if called with single argument, return struct instead of writing .mat file.

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: XLS2STRUCT, xls2struct, xls2struct