Inner matrix dimensions must agree error
이전 댓글 표시
nlen=28;
a=ones(5601,nlen);
h=ones(5600,nlen);
Q=0.01;
x=ones(5600,nlen);
w1=ones(5600,nlen);
w=w1*sqrt(Q);
x_0=xlsread('D:\ieee14\faultset.xlsx',1,'A5601:AB11201');
x(1)=a*x_0+w(1);
this is my code and i keep getting this error Error using * Inner matrix dimensions must agree. Error in x(1)=a*x_0+w(1);
how to remove it? i want to do matrix multiplication
답변 (1개)
Geoff Hayes
2017년 4월 14일
Nana - looking at your code, a is a 5601x28 matrix and w is a 5600x28 matrix. The dimensions of x_0 are unknown (from the above code anyway). Your equation is
x(1)=a*x_0+w(1);
Since you are multiplying a with x_0, then the number of rows of x_0 must be identical to the number of columns of a. This means that x_0 must have 28 (i.e. nlen) rows. From the error message, this doesn't appear to be true. What can you tell us about the dimensions of x_0? In your code, add
size(x_0)
Also, since the number of rows of a is one more than the number of rows of w, you will not be able to add the product of a with x_0 since it will have 5601 rows and the w will have 5600.
댓글 수: 6
Nana Fernandes
2017년 4월 14일
Nana Fernandes
2017년 4월 14일
Geoff Hayes
2017년 4월 14일
Nana - you are trying to assign a matrix to a single element of x so the error makes sense. Let x be a cell array instead if you want to collect all the updates to the state vector x.
x = {};
then
x{1} = a*x_0+w(1);
Since it appears that you are doing some sort of Kalman filtering, why is a a matrix of all ones? Shouldn't this be a transition matrix with ones along the diagonal and the some of the off-diagonal elements be non-zero to allow for transition from one time to the next? Because if it is all ones, then the only difference from time step t to t+1 will be because of the noise (?) w.
Why is x a 5601x28 array? What does it represent? I can't imagine a state vector having that many elements unless this is a combination of all data from all time? Or are these supposed to be observations that you feed into the filter?
Nana Fernandes
2017년 4월 14일
Nana Fernandes
2017년 4월 14일
편집: Nana Fernandes
2017년 4월 14일
Geoff Hayes
2017년 4월 16일
Nana - I think that you need to review what it is you want your Kalman filter to do. What are the observations? What is the state vector? What are you trying to model?
카테고리
도움말 센터 및 File Exchange에서 Control System Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!