compute means between files
3 views (last 30 days)
Show older comments
Hi,
I'm trying to create a series of vectors that stores the means from vectors located in a series of files. For example if file 1 (excel file) contains vector (1,2,3) and vector (4,5,6) while file 2 contains vector (7,8,9) and (10,11,12). I want to get vector 1 =(mean(1,7),mean(2,8),mean(3,9)) and vector 2=(mean(4,10),mean(5,11),mean(6,12)).
Any ideas on the shortest way to do this?
0 Comments
Answers (1)
Walter Roberson
on 5 Feb 2014
If the vectors are stored as columns in the files, each column a different vector, then
d1 = xlsread('FirstFile.xls');
d2 = xlsread('SecondFile.xls');
means = (d1 + d2)/2;
will then be vectors as a series of columns, each column the mean of the corresponding file columns.
If you have a number of files, say N of them, whose names are in "filenames" then
data = cell(N,1);
for J = 1 : N
data{J} = xlsread(filenames{J});
end
means = mean(cat(3, data{:}),3);
2 Comments
Walter Roberson
on 10 Feb 2014
My test data appears to get the right answer. Can you produce a small bit of sample data that it gets wrong?
See Also
Categories
Find more on Data Import and Analysis 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!