What is your difficulty? Do you know what a "matrix" is? If so "Create a random matrix containing 1’s, 2’s and 3’s" should be easy. To ". Display the matrix using the image command" sounds like you are using some kind of computer algebra system and I have no idea what commands it has. But I suspect you would just replace a bit in an n by n array with the color from the corresponding part of the matrix array.