Subscript indices problem

I am posting a simple code that is a part of my project code and I am facing problems. The code is as below:
imshow(img3)
[x,y] = ginput(click)
x_max = max(x);
x_min = min(x);
y_max = max(y);
y_min = min(y);
hold on
for j = x_min:x_max
for k = y_min:y_max
img(j-x_min+1,k-y_min+1) = img3(j,k);
end
end
hold off
Now the error showing is:
*??? Attempted to access img3(8,9); index must be a positive integer or logical.
Error in ==> complete_segmentation at 49 img(j-x_min+1,k-y_min+1) = img3(j,k);*
Please Note that : 'img3' is a preexisting image and 'img' is also an already existing image and I am overwriting 'img'. Is that a problem? Because the dimension of 'img' previously defined is different. However when I tried 'x_min' and 'y_min' separately in the command window i got the values as 8.0000 and 9 respectively but when i tried 'img3(j,k)' it showed an error saying subscript indices must be real integers or logicals.

 采纳的回答

GINPUT does not reply integers here. So try this:
[x,y] = ginput(click)
x = round(x);
y = round(y);
x_max = max(x);
...
The "8.0000" is something like "8.00000000000001", which cannot be used as index.

1 个评论

Thank you..I think this has served the purpose for the time being. I will let you know if the problem persists. And the explanation was nice brief and to the point. I appreciate sir

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by