Averaging columns from multiple excel files
2 views (last 30 days)
Show older comments
Hi, I have several excel files and would like to do some analysis and then average the results.
I've attached a sample file to help explain my question (the actual files have a lot more data). I wrote a sample code to get the get the first two columns in a certain time range:
file_folder = 'C:\Users\J\Desktop\'
file1 = [file_folder 'example.xls']
sheet = 1;
%get start & stop values
start = xlsread(file1, sheet, 'B4')
stop = xlsread(file1, sheet, 'B5')
%read all columns
col1 = xlsread(file1, sheet, 'A8:A18');
col2 = xlsread(file1, sheet, 'B8:B18');
time_column = xlsread(file1, sheet, 'C8:C18');
%index of start and stop value in time column
start_index = find(time_column==start)
stop_index = find(time_column==stop)
%get columns 1 and 2 in given time frame
col1_time = col1(start_index:stop_index)
col2_time = col2(start_index:stop_index)
My question now is how I can do this to several files and then compare (e.g. average) the columns? For example, I need to get all the col1_time for each file (each file has different start and stop times).
I thought I could loop through all my excel files, but then I'm overwriting the array where my data is stored. The only way I could think of is to loop through the files, create a new excel file every time and then loop through all the new files... though I'm not sure this is the best approach.
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!