Import many excel files to Matlab- How to?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
2019년 12월 15일
Ok, are the files numbered? Like
Ahvaz_0001.xlsx
Ahvaz_0002.xlsx
Or how are they named / where are they stored?
답변 (3개)
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...
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!