Borrar filtros
Borrar filtros

Attempted to access b(0,:); index must be a positive integer or logical.

1 visualización (últimos 30 días)
Andy
Andy el 17 de Abr. de 2013
for k=1:14;
[col,row]=size(b);
prj=zeros(col,1);
for i=1:col
for j=1:row
if b(i,j)==0
prj(i)=prj(i)+1;
end
end
end
rup = 0;rdw = 0;
for i = 1:col
if prj(i)==0 && prj(i+1)>=1
rup = i;
end
if prj(i)>=1 && prj(i+1)==0
rdw = i+1;
break
end
end
range = rdw-rup;
ab = ones(range,row);
for i= rup:rdw
ab(i-rup+1,:) = b(i,:);
b(i,:)=1;
end
figure;imshow(ab);
k=k+1;
end
I have some problems with the above code and I keep getting the "attempt to access" error.
The size of matrix b is [3508 2480].
Can anybody shed some like as to fix it?
I get the following error:
Attempted to access prj(3509); index out of bounds
because numel(prj)=3508.
Error in main (line 67)
if prj(i)==0 && prj(i+1)>=1

Respuestas (2)

Walter Roberson
Walter Roberson el 17 de Abr. de 2013
You start with rup = 0. You then have a loop that conditionally assigns a different value to rup. You then loop "i" starting from rup. But suppose the conditions of the conditional assignment were never true: then rup would still be 0, and you would be looping starting from 0.

Andy
Andy el 17 de Abr. de 2013
Thank you for your explanation. It seems really complicated to understand. Are there anything that I can change to make it work? Like plus 1 somewhere? Thanks!
  1 comentario
Walter Roberson
Walter Roberson el 17 de Abr. de 2013
You need to decide what you want to do if your "for i = 1:col" loop does not find any matches.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by