How to import several files of excel into a table in Matlab?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2019-6-7
3 个评论
Walter Roberson
2019-6-8
编辑:Walter Roberson
2019-6-8
datadir = 'project7\straindata';
dinfo = dir( fullfile(datadir, '*.xlsx') );
filenames = fullfile( datadir, {dinfo.name} );
numfiles = length(filenames);
for K = 1 : numfiles
thisfile = filenames{K};
thistable = readtable(thisfile);
if K == 1
datatable = thistable;
else
datatable = [datatable; thistable];
end
end
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!