MatLab 幂律,非正值误差

MatLab Power Law, Non-Positive Value Error

您好,我正在尝试使用 MatLab 的拟合函数为我的数据拟合幂模型

fo = fit(log2(x(:)),log2(y(:)),'power1');
plot(fo,'g'), hold on

然而当我运行这个我得到错误

Error using fit>iFit (line 282)
Cannot fit Power functions to data where X has nonpositive values.

Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ... 

Error in CurvedPowerLaw (line 20)
fo = fit(log2(x(:)),log2(y(:)),'power1');

查看我的数据并检查是否有小于 1 的数据时,没有显示任何内容

x(count_1)=M(i,1);
y(count_1)=M(i,2);
count_1= count_1+1;
if(M(i,2)<1)
    display(M(i,1))
end;

M 是一个包含两列的 csv 文件。我还重新 运行

的代码
if(M(i,1)<1)

没有显示任何内容。手动检查,似乎也没有低于 1。

i 只是文件中被解析的行。该文件看起来像

344,17
345,13
346,13
347,16
340,12

M(i,1) 将导致 returning >300 个数字之一,M(i,2) 将 return ~10 值 任何帮助将不胜感激!!

谢谢

虽然在按 log2 缩放它们时解析的所有值都大于 0,但 0 值开始出现。快速修复是在解析每个值时将它们加 1。