Subscript Error Plz help

조회 수: 1 (최근 30일)
Fred
Fred 2012년 10월 3일
Pk is a 1*5 , and LandaMean is 1*37 matrice
b=1
m=6
for k=1:(n-(2*b)-m+1);
Pk = LandaMean(k+1:k+m-1);
for i=k+1:k+m-1
if sum(abs(Pk(i)-LandaMean(k)))<= (2*s);
LandaU =(1/m)*sum(LandaMean(k:k+m-1));
break
else
end
end
end
But I get this error:
Subscript indices must either be real positive integers or logicals.
Error in TailDep (line 50)
if sum(abs(Pk(i)-LandaMean(k)))<= (2*s);
Thank you
  댓글 수: 1
Fred
Fred 2012년 10월 4일
Thank you, I realized that I had used sum in other lines as a parameter so it was the making problem :)

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

채택된 답변

Razvan
Razvan 2012년 10월 3일
Just look at line 50 and what vectors are there. Probably there is something like
vector(negative_number)
So check why the index is negative...
  댓글 수: 1
Fred
Fred 2012년 10월 3일
Thank you

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

추가 답변 (1개)

Image Analyst
Image Analyst 2012년 10월 3일
편집: Image Analyst 2012년 10월 3일
What is n and s? Whatever they are, they make either i or k negative or zero.
I guessed for n and s and ran this code and had no error whatsoever:
Pk = rand(1, 5);
LandaMean = rand(1, 37);
b=1;
m=6
n = 9 % Total guess
s = 10 % Total guess
for k=1:(n-(2*b)-m+1);
Pk = LandaMean(k+1:k+m-1);
for i=k+1:k+m-1
if sum(abs(Pk(i)-LandaMean(k)))<= (2*s);
LandaU =(1/m)*sum(LandaMean(k:k+m-1));
break;
else
end
end
end
Do you know how to step through code with the debugger to inspect variables?
  댓글 수: 3
Fred
Fred 2012년 10월 3일
Actually I found where is the problem but I don't know what should I do? the inside of sum becomes around 0.15 and it assumes that 0.15 is an index for sum!! but sum is a function here!
Walter Roberson
Walter Roberson 2012년 10월 3일
Are you sure that you did not accidentally create a variable with the name "sum" ? Check with
whos sum

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by