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
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
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 Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!