MATLAB: Subscript indices problem

subscript index

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.

Best Answer

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.