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 ??

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 5 Avr 2013

0 votes

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

3 commentaires

Shahd Ewawi
Shahd Ewawi le 5 Avr 2013
Modifié(e) : Azzi Abdelmalek le 5 Avr 2013
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
Azzi Abdelmalek
Azzi Abdelmalek le 5 Avr 2013
Modifié(e) : Azzi Abdelmalek le 5 Avr 2013
cc=Connected(i-1,j)
If i start from 1 then i-1 start from 0
Shahd Ewawi
Shahd Ewawi le 5 Avr 2013
Modifié(e) : Shahd Ewawi le 5 Avr 2013
thanks for your help

Cette question est clôturée.

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by