MATLAB Answers

How to import several files of excel into a table in Matlab?

13 views (last 30 days)
Dear community
When I use the function "import data", only allows to import one excel file.
The issue is, I have several excel files in one folder and I need to import all that excel files.
Anyone knows a loop that allow to import all that excel files?
Thanks in advance


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jun 2019


Jonathan Bijman
Jonathan Bijman on 8 Jun 2019
I already used that way, but only read numbers that’s the reason why I need to convert into a table using the tool “import data” from home. It doesn’t work
Walter Roberson
Walter Roberson on 8 Jun 2019
datadir = 'project7\straindata';
dinfo = dir( fullfile(datadir, '*.xlsx') );
filenames = fullfile( datadir, {} );
numfiles = length(filenames);
for K = 1 : numfiles
thisfile = filenames{K};
thistable = readtable(thisfile);
if K == 1
datatable = thistable;
datatable = [datatable; thistable];
At the end of the loop, provided all of the xlsx files had the same number of variables with the same datatypes and the same headers in the same order, then datatable will be a single table containing all of the information from the files.

Sign in to comment.

More Answers (0)