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

Answers (1)

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 Comments

after running size(x_0) i get ans =
5601 28
nlen=28;
a=ones(5601,5601);
h=ones(5601,nlen);
Q=0.01;
% R=2;
x=ones(5601,nlen);
% z=ones(1,nlen);
% xapriori=ones(5600,1);
% xaposteriori=ones(5600,nlen);
% residual=ones(11201,nlen);
% papriori=ones(11201,nlen);
% paposteriori=ones(11201,nlen);
%k=ones(11201,nlen);
%Calculate the process and measurement noise.
w1=ones(5601,nlen); %This line and the next can be commented out after running
%v1=ones(5601,nlen); %the script once to generate multiple runs with identical
%noise (for better comparison).
w=w1*sqrt(Q);
%v=v1*sqrt(R);
%Initial condition on the state, x.
x_0=xlsread('D:\ieee14\faultset.xlsx',1,'A5601:AB11201');
%Initial guesses for state and a posteriori covariance.
%xaposteriori_0=xlsread('D:\ieee14\faultset.xlsx',1,'A1:AB5600');
%paposteriori_0=1;
x(1)=a*x_0+w(1);
%z(1)=h*x(1)+v(1);
im getting this error now
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in kalman14thapril (line 26)
x(1)=a*x_0+w(1);
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?
x is a matrix that has the prior stable state values and yes the excel sheet represents a database of stable values of the system in testing
also
x{1} = a*x_0+w(1);
along with the changes u said above gives me the error
Cell contents assignment to a non-cell array object.
i even changed 'a' to
a=eye(28,5601);
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?

Sign in to comment.

Categories

Find more on Control System Toolbox in Help Center and File Exchange

Asked:

on 14 Apr 2017

Commented:

on 16 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!