Error: index out of bounds
古いコメントを表示
Hi I'm trying to execute a program but i keep getting this error:"Attempted to access dp(22); index out of bounds because numel(dp)=21"
I understand what it means, but I'm not able to fixe it, I need some help.
Here is the part of the code with the error:
for k=coef_lms:length(x) %length(X)=length(d)=403000, coef_lms=21
xp= x(k-p+1:k);
dp= d(k-p+1:k);
y(k)= h' * xp;
error(k) = dp(k) - y(k);
h = h + mu * xp * conj(error(k));
end
Thanks.
採用された回答
その他の回答 (1 件)
Amit
2014 年 1 月 18 日
I think you need to rethink how you need to write this. The reason the error is there because in every loop you are defining xp and dp.
Lets say for p is 2, the size of dp and xp in every loop will be only 2 (I think you tried p = 21, here). however in error(k), in every loop you're trying to access the k'th value which doesn't exist.
The moral of the story is:
dp= d(k-p+1:k);
does not creates matrix dp of size 1 to k and fills values only on k-p+1 to K, but it creates a matrix of size 1 to p.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!