MATLAB: How do i move two overlaid images up or down with the keyboard keys in order to match them

Image Processing Toolboxkeyboard keys functionsmanual shift image

I have the following variable: canvas=zeros([648,1024,3]); In the 3 channels I have very similiar images so that later I can compare them a find the best match. First I am going to compare the first two channels (red and green), and so if everything is matching, I should get a yellowish image. But if some parts are not matching very well, I will get either red or green pixels. So my goal is to move one of the images, up or down, with the arrow keys, in order to match them. I tried to use the following code:
function catchKeyPress
canvas=zeros([648,1024,3]);
canvas(:,:,1)= imread('transform_image1.png');
canvas(:,:,2)= imread('transform_image2.png');
h = figure;
set(h,'KeyPressFcn',@KeyPressCb) ;
I = canvas(:,:,:);
imshow(canvas,[]);
function KeyPressCb(~,evnt)
fprintf('key pressed: %s\n',evnt.Key);
for i=0
if strcmpi(evnt.Key,'uparrow')
I = [canvas(i+1:end,:,2) canvas(i+1,:,2) canvas(:,:,2)];
imshow(I,[]);
i=i+1;
end
end
for i=1
if strcmpi(evnt.Key,'downarrow')
I = [canvas(1:i,:,2) canvas(i+1:end,:,2) canvas(:,:,2)];
imshow(I,[]);
i=i+1;
end
end
end
end
So, to sum up, I would be thankful if someone could help me on this, especially the pixels' position movement with the arrow keys and the output image has to be of the same sizer as the input image. Thank you