Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
matlab中矩阵维数必须一致误差?_Matlab_Matrix - Fatal编程技术网

matlab中矩阵维数必须一致误差?

matlab中矩阵维数必须一致误差?,matlab,matrix,Matlab,Matrix,我已经为我的程序修改了一些现有的代码,但是我遇到了一个错误,我不知道原因。我有N个观测值的数据,我的目标是将数据分解成越来越小的子样本,并对每个子样本进行计算。为了确定子样本大小将如何变化,程序将查找N的除数并将其存储到数组OptN中 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 =

我已经为我的程序修改了一些现有的代码,但是我遇到了一个错误,我不知道原因。我有N个观测值的数据,我的目标是将数据分解成越来越小的子样本,并对每个子样本进行计算。为了确定子样本大小将如何变化,程序将查找N的除数并将其存储到数组OptN中

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

函数中的除数就是问题所在。我有“使用时出错。/Matrix dimensions must agree.”然而,这对长度为60的输入数据有效,但当我尝试长度为1058的数据时,它会给出上述错误。

我认为对于大型数据集,
find(max(dv)=dv)
可能会返回多个数字。因此,
OptN
将成为向量,而不是标量

然后
i
的长度(顺便说一句,在MATLAB中变量不是一个好名字,它也是一个复数i)将是不可预测的,并且可能与
n
不同,从而导致下一语句中的维度错误

您可以尝试
find(max(dv)=dv,1)
只获取第一个匹配项。或者添加一个循环