我觉得我们需要是结果,以及结果的精度,而非结果中数据的个数。
以
>> x=[1:5];
>> y=2*x
为例:
结果为
Linear model Poly1:
f(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 2 (2, 2)
p2 = -4.658e-16 (-3.172e-15, 2.24e-15)
Goodness of fit:
SSE: 1.972e-30
R-square: 1
Adjusted R-square: 1
RMSE: 8.108e-16
若是楼主真得需要,推荐楼主去看操作生成的代码
function [fitresult, gof] = createFit(x, y)
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'poly1' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel( 'x' );
ylabel( 'y' );
grid on
其实我已经看到了这里几个函数的帮助,没有发现可以设置拟合数据的长度的。
希望对楼主有帮助,谢谢。