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!