我有12
个数据点x n
个会话的时间序列。所有值都在一列中。
我想对所有会话进行平均,以便获得仅包含12
个数据点的1个系列。例如,我可以:
[a1 a2 ... a12 b1 b2 ... b12 c1 c2 ... c12]
结果应为[mean(a1, b1, c1) mean (a2, b2, c2)... mean(a12, b12, c12)]
有人可以帮我在Matlab中有效地做到这一点吗?
谢谢!
答案 0 :(得分:0)
原始系列中的元素数量始终是12的倍数,因此您可以使用reshape()
生成12 x n矩阵。从那里使用mean()
可以直接获得所需的矢量。
nSessions = 20; % Choose an integer to test number of sessions
TestData = 1:12; % Dummy data - col 1 = 1, col 2 = 2...to check that our reshaping is correct
data = repmat(TestData, 1, nSessions); % Test data of the expected form
reshapeData = reshape(data, 12, []); % Reshape into an 12 x N matrix;
meanData = mean(reshapeData, 2); % Take mean along rows to yield desired answer