2013-02-28 115 views
0

我已經爲我的程序改編了一些現有的代碼,但是我遇到了一個我不知道原因的錯誤。我有N個觀測數據,其中我的目標是將數據分解爲越來越小的子樣本,並對每個子樣本進行計算。爲了確定子採樣大小將如何改變,程序找到N的除數並將其存儲到數組OptN中。矩陣維必須在matlab中同意錯誤?

dmin = 2; 
% Find OptN such that it has the largest number of 
% divisors among all natural numbers in the interval [0.99*N,N] 
N = length(x); 
N0 = floor(0.99*N); 
dv = zeros(N-N0+1,1); 
for i = N0:N, 
    dv(i-N0+1) = length(divisors(i,dmin)); 
end 
OptN = N0 + find(max(dv)==dv) - 1; 
% Use the first OptN values of x for further analysis 
x = x(1:OptN); 
% Find the divisors >= dmin for OptN 
d = divisors(OptN,dmin); 

function d = divisors(n,n0) 
% Find all divisors of the natural number N greater or equal to N0 
i = n0:floor(n/2); 
d = find((n./i)==floor(n./i))' + n0 - 1; % Problem line 

在函數中,除數是發生問題的地方。我有'錯誤使用./矩陣尺寸必須同意'。但是,這與長度爲60的輸入數據一起工作,但是當我嘗試長度爲1058的數據時,它給了我上述錯誤。

回答

0

我認爲,大數據集有可能find(max(dv)==dv)將返回多個數字。所以OptN將成爲一個向量,而不是標量。

然後長度爲i(順便說一句,在MATLAB中它不是一個很好的變量名,它也是一個複數i)將是不可預知的,可能與n不同,導致下一個語句中的維度錯誤。

您可以嘗試find(max(dv)==dv,1)而不是僅獲得第一個匹配項。或者添加一個循環。