MATLAB: Inner matrix dimensions must agree. error

MATLABmatlab function errorsimulink

Hi everybody. I'm very news in matlab. I try to design kalman filter but the error occurred 'Inner matrix dimensions must agree' in matlab function
function [ x, P] = kalman( z, Q, R, x_old, P_old, A, H)
I = eye(3);
% Measurement update
K = (P_old * H') / (H*P_old*H'+R);
x = x_old + K * (z - H*x_old);
P = (I-K*H)*P_old;
% Time update
x = A * x ;
P = A * P * A' + B*Q*B';
Maybe initial estimates of P_old and x_old is not set I think. How to set that value? I want to set the first value for x and P are [0 ; 0 ;0 ] and [0.1 0 0; 0 0.1 0; 0 0 0.1] but dont know how to do.

Best Answer

As you said in your question, in your delay block you must set initials conditions to x0 and P0, where x0=zeros(n,1); n is your system order, and P0=0.1*eye(n). in your case n=3