This is what the error says "In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in KF (line 6)Xhat(i) =zeros(3,1);
How do I solve this.
A = [0.7474 0.453 0.0735; -0.441 -0.06106 0.01205; -0.0723 -0.5735 -0.1334]; B = [0.0421 0.0735 0.01205]'; C = [20 9 1]; U = 0; H = 1;z = -0.37727 + 0.1*randn(50,1)Xhat(i) =zeros(3,1);P = eye(3,3);Q = 0.00001R = 0.01for(i=2:50) X_(i) = A*Xhat(i-1) + B*U; P = A*P*A' + Q; K = P*H'*inv(H*P*H' + Q) Xhat(i) = X_(i) + K*(z(i)-H*X_(i)); P = (eye(1,1)-K*H)*P;endfigureplot([1:50],z,'rs')hold onplot([1:50], -0.37727*ones(1,50),'k')plot([1:50], Xhat,'g')
Best Answer