Inner matrix dimensions must agree. error
古いコメントを表示
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.
5 件のコメント
Walter Roberson
2012 年 12 月 4 日
Which line is the error occurring on? What are the size of each of the variables at that point? You might want to type in the command
dbstop if error
and then run your program; it will stop at the error location and allow you to examine values.
Khoa
2012 年 12 月 4 日
Walter Roberson
2012 年 12 月 4 日
What size are P_old and H ?
Question: are you sure you want algebraic matrix division? Matrix inverse of one of the parts, matrix multiplied by the other part? Or are you wanting element-by-element division which uses the ./ operator instead of the / operator?
Khoa
2012 年 12 月 4 日
編集済み: Walter Roberson
2012 年 12 月 4 日
Walter Roberson
2012 年 12 月 4 日
Please go in with the debugger, with dbstop if error, run until the problem occurs, and then try the subexpressions to see which part is generating the error
(P_old * H')
(H*P_old*H'+R)
and then if neither of those, finally
(P_old * H') / (H*P_old*H'+R)
With the array sizes you report, I do not reproduce the error.
I have to wonder about possibilities such as on the first iteration, something might be empty or an unexpected size.
採用された回答
その他の回答 (1 件)
カテゴリ
ヘルプ センター および File Exchange で Control System Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!