Index exceeds matrix dimensions.

4 visualizaciones (últimos 30 días)
Stelios Fanourakis
Stelios Fanourakis el 17 de Sept. de 2017
Editada: Stephen23 el 17 de Sept. de 2017
why??
D = zeros(size(M,1),size(M,1),size(M,2));
for k=(size(M,2)-1):-1:1
P_pred = A(:,:,k) * P(:,:,k) * A(:,:,k)' + Q(:,:,k);
D(:,:,k) = P(:,:,k) * A(:,:,k)' / P_pred;
M(:,k) = M(:,k) + D(:,:,k) * (M(:,k+1) - A(:,:,k) * M(:,k));
P(:,:,k) = P(:,:,k) + D(:,:,k) * (P(:,:,k+1) - P_pred) * D(:,:,k)';
end
the error is for line P_pred = A(:,:,k) * P(:,:,k) * A(:,:,k)' + Q(:,:,k);

Respuestas (1)

Stephen23
Stephen23 el 17 de Sept. de 2017
Editada: Stephen23 el 17 de Sept. de 2017
Because you are trying to access some part of an array that does not exist. Just like this:
>> A = rand(4,3,2);
>> A(:,:,99)
??? Index exceeds matrix dimensions.
>>
My example array only has size 2 along the third dimension, so what do you expect to happen if I try to access the 99th position along the third dimension?
If you really want to learn how to write and debug your own code then one very important skill is to start actually looking at your code. You could have very easily figured this error out yourself by looking at each of the variables, and trying each part of that line: break it down into atomic operations, and trying them in the command line. And by reading the error message of course.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by