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

6 ビュー (過去 30 日間)
Jonathan Bijman
Jonathan Bijman 2019 年 6 月 7 日
編集済み: Walter Roberson 2019 年 6 月 8 日
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

採用された回答

Walter Roberson
Walter Roberson 2019 年 6 月 7 日
  3 件のコメント
Walter Roberson
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.
Jonathan Bijman
Jonathan Bijman 2019 年 6 月 8 日
Thank u, thank u, thank u so much!!!
it works! =)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by