Borrar filtros
Borrar filtros

index must be a positive integer or logical.

1 visualización (últimos 30 días)
hayat ali
hayat ali el 22 de Nov. de 2018
Comentada: Walter Roberson el 22 de Nov. de 2018
I am getting the following error while running the code:
Attempted to access (1,NaN); index must be a positive integer or
logical.
Error in
sh_row(i,(col+j-k(i)))=rgb(i,j);
% IF k is even right shift row else left shift row%%%%%%%%%%%%%%%%%
for i=1:1:row
for j=1:1:col
if(mod(k(i),2)==0)
if((j+k(i))<=col) %shift right of row
sh_row(i,j+k(i))=rgb(i,j);
row_shift_even(i,j)=j+k(i);
else
sh_row(i,(j+k(i)-col))=rgb(i,j); %HERE
row_shift_even(i,j)=(j+k(i)-col);
end
else
if((j-k(i))>=1) %shift left of row
sh_row(i,j-k(i))=rgb(i,j);
row_shift_odd(i,j)=j-k(i);
else
sh_row(i,(col+j-k(i)))=rgb(i,j);
row_shift_odd(i,j)=col+j-k(i);
end
end
end
end
  2 comentarios
Walter Roberson
Walter Roberson el 22 de Nov. de 2018
You had bolded the line
sh_row(i,(j+k(i)-col))=rgb(i,j);
as if it were the one the error is occuring on, but the error is occuring further down, at
sh_row(i,(col+j-k(i)))=rgb(i,j);
Walter Roberson
Walter Roberson el 22 de Nov. de 2018
We have no information about the range of values in k(i). If k(i) were large then j-k(i) could be negative, and so would fail the j-k(i)>=1 test. If it were large enough, then col+j-k(i) could be negative or 0 in the line the problem is occuring on.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations 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