Effacer les filtres
Effacer les filtres

How to import numerous excel files into MATLAB?

35 vues (au cours des 30 derniers jours)
Frank
Frank le 10 Mai 2011
Commenté : Nicolò Biagi le 22 Fév 2018
A have several excel files that I need to modify through MatLab and export into a different folder. I need help with importing and exporting an entire folder of excel files.
Thanks,
-Frank
source_dir = 'C:\Users\xuf\Desktop\Excel Saved PointScans'
dest_dir = 'C:\Users\xuf\Desktop\Test Folder'
source_files = dir(fullfile(source_dir, '*.xls'));
for i = 1:length(source_files)
data = xlsread(fullfile(source_dir,source_files(i).name));
xlswrite(fullfile(dest_dir,source_files(i).name));
end

Réponse acceptée

Will Dampier
Will Dampier le 10 Mai 2011
You won't be able to load them all at once but you could easily use a for-loop to process them one at a time. Something like this:
source_dir = 'path/to/source/'
dest_dir = '/path/to/dest'
source_files = dir(fullfile(source_dir, '*.xls'));
for i = 1:length(source_files)
data = xlsread(fullfile(source_dir, source_files(i).name)));
#do something with data
xlswrite(fullfile(dest_dir, source_files(i).name)));
end
  14 commentaires
Image Analyst
Image Analyst le 4 Juil 2016
You need to pass it a filename. You need to call it multiple times if you have multiple filenames.
Nicolò Biagi
Nicolò Biagi le 22 Fév 2018
can you give us an example on how to do it?
Thanks

Connectez-vous pour commenter.

Plus de réponses (2)

Michael Chavez
Michael Chavez le 20 Fév 2015
This has been a helpful thread for a project that I am working on. So thank you, Frank, for asking it and thank you to all that have responded.
I would like to add and ask is it possible to change the names of the output files from xlswrite, rather than the output file being the same name as the corresponding input file?
Arnaud, I was looking at the documentation for dir and I'm not sure that I saw how to generate a name for the list of output files or maybe I am overlooking the function to change the name. I am using MATLAB 7.8.0 (R2009a) for the record.

Arnaud Miege
Arnaud Miege le 10 Mai 2011
Have a look at the documentation and use dir to generate the list of file names in the folder.
HTH,
Arnaud

Community Treasure Hunt

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

Start Hunting!

Translated by