index must be a positive integer or logical

Attempted to access Connected(0,936); index must be a positive integer or logical.
Error in ==> coc at 36 cc=Connected(i-1,j);
anyone knows how to solve this ??

Answers (1)

You can not use 0 as index, it must be 1,2,3,... or logical(1) and logical(0)

3 Comments

I started the 2 for loops from 1 I don't know why it started from 0
for i=1:r
for j=1:c
p=bwZ(i+1,j+1);
if(p==1) %foreground pixel "white!"..
top=bwZ(i,j+1);
left=bwZ(i+1,j);
if(~top && ~left)
cc=mark;
equivalence(cc)= max(equivalence)+1;
mark=mark+1;
else if(top && left )
cc=Connected(i,round(j-1));
if(equivalence(Connected(i-1,j)) ~= equivalence(Connected(i,j-1)))
equivalence(Connected(i,j-1)) = equivalence(Connected(i-1,j));
end
else if(left)
cc=Connected(i,j-1);
else
if(top)
cc=Connected(i-1,j);
end
end
end
end
Connected(i,j)=cc;
end
end
end
cc=Connected(i-1,j)
If i start from 1 then i-1 start from 0
thanks for your help

This question is closed.

Asked:

on 5 Apr 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!