index must be a positive integer or logical.

조회 수: 1 (최근 30일)
hayat ali
hayat ali 2018년 11월 22일
댓글: Walter Roberson 2018년 11월 22일
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