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.

 채택된 답변

Walter Roberson
Walter Roberson 2014년 1월 18일

0 개 추천

You have
dp= d(k-p+1:k);
that is going to give you something which is (k)-(k-p+1)+1 = p elements long.
You then have
error(k) = dp(k) - y(k);
which attempts to use dp as if it is k elements long. But dp is p elements long, so that is going to fail unless p >= k. But if p >= k then (k-p+1) of the first line is only going to be positive if k == p exactly. And next iteration, when k increased, you would have to have a failure.
I would point out that you never use any other element of dp within the loop, so there does not seem to be any point in extracting dp exact to be able to find the k'th element of it for the error term. Perhaps what you want is just
dp = d(k);
and then
error(k) = dp - y(k);
I have not examined this for reasonableness of the overall operation, only for consistency in indexing.

댓글 수: 1

pep
pep 2014년 1월 18일
Thank you very much, I did that and I fixed the error, thanks again.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Amit
Amit 2014년 1월 18일

0 개 추천

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.

댓글 수: 1

pep
pep 2014년 1월 18일
Thanks for the explanation, now I could fix the error

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

pep
2014년 1월 18일

댓글:

pep
2014년 1월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by