- learn something about how to use MATLAB.
- waste less time asking random strangers on the internet how to write code. In the time you write a question and wait for an answer your could have read the documentation and tried some examples, and discovered for yourself what the problem is. Do you imagine that you are the first person to ever get that error message? That there are no explanations anywhere to help you?
Inner matrix dimensions must agree.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stelios Fanourakis
el 17 de Sept. de 2017
Respondida: Walter Roberson
el 18 de Sept. de 2017
D = zeros(size(A,1),size(A,2));
for k=1:size(A,1),size(A,2)
P_pred = A(:,k) * P(:,k) * A(:,k)' + Q(:,k);
The problem is at P_pred line. Why??
1 comentario
Stephen23
el 17 de Sept. de 2017
Editada: Stephen23
el 17 de Sept. de 2017
@ Stelios Fanourakis: you are posting one question every ten minutes, each one suffixed with the simple question "why?"
I can tell you the answer to all of your "why"s: because you clearly have not bothered to read the documentation for any function or operation that you are using.
Now you are asking about one small line containing three operators and some indexing. Did you read the documentation for any of them? If you had, you would:
It is clear that you did not put in much effort into reading the documentation, searching this forum, using the internet, or experimenting with the problems you are having. I do not know of any forum where these traits are appreciated and valued.
You need to start learning how to identify and fix problems yourself. Atleast put in some effort.
Respuestas (1)
Walter Roberson
el 18 de Sept. de 2017
The * operator is algebraic matrix multiplication. In the expression A * B, if A is m x n, and B is p * q, so (m x n) * (p * q) then following the rules of matrix multiplication, the "inner dimensions" must be the same size -- that is, n = p -- so (m x n) * (n * q) which gives an m x q result size.
You have
A(:,k) * P(:,k)
as part of your calculation, where k is a scalar. For that to work, the first dimension of P would have to be scalar -- A could be m x n but P would have to be 1 x q, and that would give an m x q result. Then you multiply that by A(:,k)' which is a (m x 1)' which is a 1 x m, so you are multiplying a (m x q) by (1 x m). For the 1 to match, q would have to be 1, so we have deduced that P must be 1 x 1, a scalar, so so we are working with (m x 1) * (1 x 1) * (1 x m) giving an m x m result.
You then add Q(:,k), which is r x 1, to that m x m matrix. With all versions up to and including R2016a, in order to add an m x m matrix to an r x 1 matrix, either m would have to be 1 so a 1 x 1 + r x 1, or r would have to be 1, so m x m + 1 x 1.
With version R2016b and later, in order to add an m x m matrix to an r x 1 matrix, either m would have to be 1 so a 1 x 1 + r x 1, or r would have to be 1, so m x m + 1 x 1, or m would have to be r, so m x m + m x 1, which would be defined the same way as bsxfun(@plus, m x m matrix, m x 1 matrix) which would be the same as m x m matrix + repmat(m x 1 matrix, 1, m).
... Might I suggest to you that what you actually wanted was to use the .* element-by-element multiplication operator rather than the * algebraic matrix multiplication operator?
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!