Import many excel files to Matlab- How to?

3 vues (au cours des 30 derniers jours)
BN
BN le 15 Déc 2019
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 commentaires
Turlough Hughes
Turlough Hughes le 15 Déc 2019
Ok, are the files numbered? Like
Ahvaz_0001.xlsx
Ahvaz_0002.xlsx
Or how are they named / where are they stored?
BN
BN le 15 Déc 2019
no they have very different names (city names) but all of them are in E:\test\ folder.

Connectez-vous pour commenter.

Réponses (3)

dpb
dpb le 15 Déc 2019
"...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 le 15 Déc 2019
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 le 15 Déc 2019
Since this is a VERY Frequently asked question, see The FAQ

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by