How to import several files of excel into a table in Matlab?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jonathan Bijman
am 7 Jun. 2019
Bearbeitet: Walter Roberson
am 8 Jun. 2019
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Jun. 2019
3 Kommentare
Walter Roberson
am 8 Jun. 2019
Bearbeitet: Walter Roberson
am 8 Jun. 2019
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!