Index exceeds matrix dimensions.

1 回表示 (過去 30 日間)
Stelios Fanourakis
Stelios Fanourakis 2017 年 9 月 17 日
編集済み: Stephen23 2017 年 9 月 17 日
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);

回答 (1 件)

Stephen23
Stephen23 2017 年 9 月 17 日
編集済み: Stephen23 2017 年 9 月 17 日
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.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by