2013-04-17 63 views
0

我想知道如果我能得到這個幫助。我有很多.mat文件,每個文件中都有一個數組,我想分別平均每個單元格(平均所有(1,1)s,所有(1,2)s,...(2,1)s等)和存儲它們。matlab上很多文件的平均值

感謝您的幫助!

回答

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,而不必每次都進行計數,但這取決於您獲取數據的位置。希望你明白!

+1

用'。/'替換'/',用於元素劃分。 – Pursuit

+1

如果'xCount'是一個標量,它應該沒關係。 – bla

+0

@Pursuit正如natan所說,我特意將它留下,因爲它只是一個標量。 – jazzbassrob