Homework 2: Due Midnight on Tuesday October 13th.

Part 1:

Create the following matrix M:

[2 2 2 2 2 2
1 2 2 2 2 2
1 1 2 2 2 2
1 1 1 2 2 2
1 1 1 1 2 2
1 1 1 1 1 2]

by using a nested for loop where the variable i loops through the rows and j loops through the columns. Inside the loop, use an if statement so that if the row value is greater then the column value (i>j) set that element of the matrix to 1, otherwise set it to 2.

Part 2:

Create a color map containing two colors, red and green. Use the image commmand and colormap command to show the matrix M that you made above using the red and green color map. The image should look like this:

hw2img1

Part 3

Create a new matrix N so that when you show it using the image command, using the same red green color map from part 2, you get a picture like the one below. Try making it with a nested for loop, but if you can't it's OK to define it by hand.

hw2img2