2013-02-28 113 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)而不是仅获得第一个匹配项。或者添加一个循环。