我有一组向量“measured_data”,其中包含 200 个正浮点值的样本数据。我很难找到适合这个数据的模型。下面的代码在每一步都返回错误,即在评论预测()时,下一个命令抛出另一个错误......所以似乎没有任何工作。我彻底去了通过文档,我似乎无法理解问题出在哪里以及哪里出错了。如果有人可以通过代码并帮助减轻问题,我将不胜感激。谢谢。
Undefined function 'predict' for input
arguments of type 'double'.
Error in Untitled (line 157)
model2_pred = predict(model2_coeff, model2_data, 1);
代码
model1 = ar(measured_data, 2,'yw');
model2 = ar(measured_data, 5,'yw');
coeffs1 = model1.a;
model1_coeff=[coeffs1(2) coeffs1(3)]
coeffs2 = model2.a;
model2_coeff=[coeffs2(2) coeffs2(3) coeffs2(4) coeffs2(5)]
x(1) = 0.0;
x(2) = 0.0;
y(1) = 0.0;
y(2) = 0.0;
y(3) = 0.0;
y(4) = 0.0;
%Solve for Model1 by putting in the coefficient values
for i=3:200
x(i) = coeff1(2) *x(i-1) +coeff2(3)*x(i-2) ;
end
model1_data=x;
%Solve for Model2 by putting in the coefficient values
for i=5:200
y(i) = coeff2(2) *y(i-1) +coeff2(3)*y(i-2) +coeff2(4)*y(i-3) +coeff2(5)*y(i-4) ;
end
model2_data=y;
model1_pred = predict(model1_coeff, model1_data, 1);
model1_residual=model1_data-model1_pred;
model1_err = resid(model1_coeff,measured_data); %prediction errors
model2_err = resid(model2_coeff,measured_data);
subplot(1,2,1);
plot(model1_err);
subplot(1,2,2);
plot(model2_err);
model1_mse=sqrt(mean((measured_data-model1_coeff).^2)); %Mean square error
model2_mse=sqrt(mean((measured_data-model2_coeff).^2));
compare(measured_data,model1_coeff,'g',model2_coeff,'b');