Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
reading multiple excel files

Subject: reading multiple excel files

From: Chris Rock

Date: 18 Aug, 2010 12:29:10

Message: 1 of 5

Hi,

I have a large number of excel files, each one representing a vehicle trip. All of the files have the same column layout, in that the same parameters are in the same columns in all of the files.

Currently, I have been able to write a function which will read in a single excel file, perform some simple analysis and then write the results of the analysis into a separate summary excel file for that particular trip.

I ultimately want to have all of the analysis results for the trips (i.e.: all of the separate excel files) in a single summary excel file, with each row containing the analysis information for each trip. Unfortunately, I'm stuck at how to read in multiple excel files without sitting here and running the function repeatedly, analysing each source excel file in turn.

Is there any way to read multiple excel files and to then write the analysis results from each into a single, common excel file? Apologies if this is something rudimentary - I'm on a very steep learning curve.

Many thanks,

Chris

Subject: reading multiple excel files

From: Andy

Date: 18 Aug, 2010 12:40:30

Message: 2 of 5

"Chris Rock" <chris.rock@cenex.co.uk> wrote in message <i4gjmm$hid$1@fred.mathworks.com>...
> Hi,
>
> I have a large number of excel files, each one representing a vehicle trip. All of the files have the same column layout, in that the same parameters are in the same columns in all of the files.
>
> Currently, I have been able to write a function which will read in a single excel file, perform some simple analysis and then write the results of the analysis into a separate summary excel file for that particular trip.
>
> I ultimately want to have all of the analysis results for the trips (i.e.: all of the separate excel files) in a single summary excel file, with each row containing the analysis information for each trip. Unfortunately, I'm stuck at how to read in multiple excel files without sitting here and running the function repeatedly, analysing each source excel file in turn.
>
> Is there any way to read multiple excel files and to then write the analysis results from each into a single, common excel file? Apologies if this is something rudimentary - I'm on a very steep learning curve.
>
> Many thanks,
>
> Chris

See http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_process_a_sequence_of_files.3F

I'd also like to ask: how are you reading in your Excel file? If you are using xlsread, you wouldn't want to do that in a loop, since it will open and close an instance of Excel every time. Instead, you should use actxserver (before the loop) to open Excel once. Then process your files. Then close Excel once.

Subject: reading multiple excel files

From: machatsk

Date: 18 Aug, 2010 12:48:22

Message: 3 of 5

"Chris Rock" <chris.rock@cenex.co.uk>
> Is there any way to read multiple excel files and to then write the analysis results from each into a single, common excel file? Apologies if this is something rudimentary - I'm on a very steep learning curve.

    If all of the Excel sheets are in the same location, have the function get all of the filenames (with a for loop) and place them into an array. Then with another for loop inside of your current function, pass each filename one by one to xlsread().

   The information gathered from xlsread() can be stored into a single array at the end of each pass for the loop, so when the function is done you'll have all of your data in one array, which you can write to a single Excel sheet. Maybe this will get you started:

%all_filenames will be the array with all of the excel sheets
     for a=1:length(all_filenames)
                [data]=xlsread(all_filenames(a), etc etc
                 info array(#:#)=data(#:#)
     end
              Maxx

Subject: reading multiple excel files

From: machatsk

Date: 18 Aug, 2010 12:49:37

Message: 4 of 5

"Chris Rock" <chris.rock@cenex.co.uk>

A loop will take a while though...

Subject: reading multiple excel files

From: Chris Rock

Date: 18 Aug, 2010 13:11:24

Message: 5 of 5

Thanks very much, guys.

I'll try your suggestions this afternoon and see if I can get it working.

Thanks again for your help.

Chris

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us