Import many excel files to Matlab- How to?

조회 수: 3 (최근 30일)
BN
BN 2019년 12월 15일
답변: Image Analyst 2019년 12월 15일
Hey all I have over 50 .xlsx file in E:\test\ directory. how to import them in matlab in order to conduct some future performs?
thank you
  댓글 수: 4
Turlough Hughes
Turlough Hughes 2019년 12월 15일
Ok, are the files numbered? Like
Ahvaz_0001.xlsx
Ahvaz_0002.xlsx
Or how are they named / where are they stored?
BN
BN 2019년 12월 15일
no they have very different names (city names) but all of them are in E:\test\ folder.

댓글을 달려면 로그인하십시오.

답변 (3개)

dpb
dpb 2019년 12월 15일
"...they have very different names (city names) but all of them are in E:\test\ folder."
Ok so just use the dir() solution (my preference almost always)...
rootdir='E:\test';
d=dir(fullfile(rootdir,'*.xlsx')); % return list of .xlsx files in given subdirectory
for i=1:numel(d)
t=readtable(fullfile(d(i).folder,d(i).name)); % use readtable here for example, choose whatever best for your use
% do whatever with each file here...
...
end
As noted, above uses readtable as convenient way to read .xls files; there are other options depending upon just what the file structure is and what need to do with them...

Turlough Hughes
Turlough Hughes 2019년 12월 15일
If all your data files are in that folder, and only your data files are in that folder and they are formatted the same, the following should work:
filepath='E:\test\folder'
fils=dir(filepath);
opts=detectImportOptions(fullfile(filepath,fils(1).name));
for c=1:length(fils)
s.([fils(c).name])=readtable(fullfile(filepath,fils(c).name),opts);
end
You would in this case be saving to a struct called s.
I am depending on the files having the same format, alternatively you might use detectImportOptions on each iteration of the loop.

Image Analyst
Image Analyst 2019년 12월 15일
Since this is a VERY Frequently asked question, see The FAQ

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by