No idea at all what this (what you asked : "Hello. How to merge images vertically and horizontally by changing the color of the matrix cell indicate with green and red.") means. See link below before you fix your post.
so all I can offer other than the link above is to look at imtile() or montage() to stitch images together, or to do it manually:
tiledImage = [image1, image2; image3; image4];

