index must be a positive integer or logical.

1 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2018-11-22
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 2018-11-22
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by