matlab上许多文件的平均值

时间:2013-04-17 22:42:16

标签: matlab

我想知道我是否能得到这方面的帮助。我有很多.mat文件,每个都有一个数组,我想单独平均每个单元格(平均所有(1,1)s,所有(1,2)s,...(2,1)s等)和存储它们。

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

我不太确定您的数据是如何组织的,但您可以这样做:

% Assume you know the size of the arrays and that the variables r and c
% hold the numbers of rows and columns respectively.

xTotals = zeros(r, c);
xCount = 0;


% for each file: assume the data is loaded into a variable called x, which is
% r rows by c columns
for ...
  xTotals = xTotals + x;
  xCount = xCount + 1;
end

xAvg = xTotals / xCount;

xAvg将包含每个阵列单元的平均值。请注意,您可能只需知道xCount,而不必在每次循环时计算,但这取决于您获取数据的位置。希望你明白了!