i want to replace 2 pixels in the matrix by using this function between two pixels throw me this error
이전 댓글 표시
for k=1:ch2
for i=1:r2
for j=1:c2
if New_im(i,j,k) >New_im(i+3,j,k)
New_im(i+1,j,k)=New_im(round((((New_im(i,j,k) - New_im(i+3,j+3,k))/fact)*2) + New_im(i,j,k)),j,k) ;
New_im(i+2,j,k)=New_im(round((((New_im(i,j,k) - New_im(i+3,j+3,k))/fact)*1) + New_im(i,j,k)),j,k) ;
end
end
end
end
error that throwd
Index in position 1 is invalid. Array indices must be positive integers or logical values.
댓글 수: 1
Image Analyst
2022년 3월 15일
What is the value of i, i+2, and i+3 when it throws the error? Are any of them floating point (have fractional parts), zero, negative, or larger than the number of rows in the New_im array?
What are the values of ch2, r2, c2, and fact?
You can reply after you read this:
답변 (2개)
Jan
2022년 3월 15일
Use the debugger to examine the problem:
dbstop if error
Then run the code again. When Matlab stops in the failing line, check the locally used variables. I guess that this is the line:
New_im(i+1,j,k)=New_im(round((((New_im(i,j,k) - New_im(i+3,j+3,k))/fact)*2) + New_im(i,j,k)),j,k);
Then check in the command window:
i, j, k
New_im(i,j,k)
(((New_im(i, j, k) - New_im(i+3, j+3, k)) / fact) * 2
round((((New_im(i, j, k) - New_im(i+3, j+3, k)) / fact) * 2) + New_im(i,j,k))
Obviously the index is not a positive integer.
댓글 수: 1
Walter Roberson
2022년 3월 15일
Note in particular that the result of the round() + New_img(i,j,k) is being used as a index into New_im
Voss
2022년 3월 15일
Is this what you mean to do?
for k=1:ch2
for i=1:r2
for j=1:c2
if New_im(i,j,k) > New_im(i+3,j,k)
diff_im = (New_im(i,j,k) - New_im(i+3,j+3,k))/fact;
New_im(i+1,j,k) = round(diff_im*2 + New_im(i,j,k));
New_im(i+2,j,k) = round(diff_im + New_im(i,j,k));
end
end
end
end
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!