0

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

谢谢您的帮助!

4

1 回答 1

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无需每次循环计算就知道,但这取决于您从哪里获取数据。希望你明白这一点!

于 2013-04-17T22:50:09.227 回答