get the following error message when I have have a variable QUEUE
and then for i:2500, I loop through QUEUE(i). I don't understand why
Matlab is attempting to access QUEUE(-2.14748e+009)....Can anyone
help me with this error? I suspect it might be a floating point
problem, is it possible?
----------------------

??? Attempted to access QUEUE(-2.14748e+009); index must be a
positive integer or logical.

Error in ==> CompBNodeMeas at 15
QUEUE(i)=0;
--------------------------

The strange thing is that it doesn't happen every time. Sometimes I get the error, sometimes the program executes till completion.

Any help would be greatly appreciated.

The source code is appended below. Many apologies and really appreciate any help from anyone.
--------------------------------------
for i=1:50
Bcount(i)=0;
end

% start considering node k as head
for k=1:50

%initialize queue
index=1; %index points to the current empty cell on QUEUE
for i=1:(50*50)
QUEUE(i)=0;
end

%reset level values
for i=1:50
Level(i)=0;
end
%set level for k as -1
Level(k)=-1;

%reset anc matrix
for i=1:50
for j=1:50
anc(i,j)=0;
end
end

%look for vertices adjacent to k
for n=1:50
if A(k,n)==1 %A(k,n) is 1 if vertex k is adjacent to n
%put n on QUEUE and shift index
QUEUE(index)=n;
index=index+1;
%set n on level 1
Level(n)=1;
%put n on its own anc list
anc(n,n)=1;
end
end

while index~=1
% pop the first vertex from QUEUE
r=QUEUE(1);

for n=1:50
if ((n~=k)&(A(r,n)==1)&(Level(n)==Level(r)+1)) %if n has been visited before
for i=1:50
if anc(r,i)~=0
Bcount(i)=Bcount(i)+anc(r,i);
end
end
for i=1:50
anc(n,i)=anc(n,i)+anc(r,i);
end
if anc(r,r)>=2
anc(n,n)=anc(n,n)+anc(r,r);
else
anc(n,n)=anc(n,n)+1;
end
end

if((n~=k)&(A(r,n)==1)&(Level(n)==0)) %if n has not been visited before
%put n on QUEUE and shift index
QUEUE(index)=n;
index=index+1;
%set n's level
Level(n)=Level(r)+1;

for i=1:50
if anc(r,i)~=0
Bcount(i)=Bcount(i)+anc(r,i);
end
end
for i=1:order
anc(n,i)=anc(n,i)+anc(r,i);
end
if anc(r,r)>=2
anc(n,n)=anc(n,n)+anc(r,r);
else
anc(n,n)=anc(n,n)+1;
end
end
end

%shift entries in QUEUE and adjust index
for i=1:(index-1)
QUEUE(i)=QUEUE(i+1);
end
index=index-1;
end %end popping nodes from QUEUE

end %end considering all nodes k as head
-------------------------