It sounds like you want to add a mouse-click callback to your image, which is a function that gets called whenever you click inside the image:
colors = [0 0 0; 1 1 1];
inds = 1:25;
color_inds = 1+mod(inds,2);
r = colors(color_inds,1);
g = colors(color_inds,2);
b = colors(color_inds,3);
checkers = cat(2,r,g,b);
checkers = reshape(checkers,[5,5,3]);
im = imagesc(checkers); % Store the image
axis equal tight;
im.ButtonDownFcn = @clickCallback; % Add the callback
function clickCallback(src, event)
pos = get(gca,'CurrentPoint'); % You can obtain the coordinates of the click like this
disp(pos)
end
Then you'll want to determine which square the user clicked inside and update it's color.
More about the mouse-click callback: https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.image-properties.html#d120e595216
More about CurrentPoint: https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html#d120e60454
Hopefully this helps!
