Error: index out of bounds
Show older comments
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.
Accepted Answer
More Answers (1)
Amit
on 18 Jan 2014
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.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!