# 2013F002/HW6

HW #6 Name:_______________________________ Section (circle one) 9am or 10:30am

Due on Thursday Oct. 17th at the beginning of class

These problems are based on Nested_For_Loops, If_Statement, Color_Representations, and Color_Maps.

# 1.

Write a program with a nested for loop and one or more if statements that will produce the following output. If you have problems, write out your program in long-hand to help you figure out why you are not getting the expected answer.

M =
0     0     0     0     0
0     0     0     0     0
0     0     0     0     0
-1    -1    -1    -1    -1
0     0     0     0     0


# 2.

Write a program with a nested for loop and one or more if statements that will produce the following output. If you have problems, write out your program in long-hand to help you figure out why you are not getting the expected answer.

 M=
0   0   0    0   -1
0   0   0   -1   -1
0   0  -1   -1   -1
0  -1  -1   -1   -1
-1  -1  -1   -1   -1

count =

15


# 3.

Write a program with a nested for loop and one or more if statements that will produce the following output. If you have problems, write out your program in long-hand to help you figure out why you are not getting the expected answer.

 M =
0     0     0     0     0
-1    -1    -1    -1    -1
0     0     0     0     0
-2    -2    -2    -2    -2
0     0     0     0     0

count =

10


# 4.

Write a program with a nested for loop and one or more if statements that will produce the following output. If you have problems, write out your program in long-hand to help you figure out why you are not getting the expected answer.

M =
0     0    -1     0     0
-1    -1    -1    -1    -1
0     0    -1     0     0
0     0    -1     0     0
0     0    -1     0     0

count =

9


# 5.

Which of the following matrices are consistent with the image and colorbar shown? (You may use MATLAB to check your answer.)

 A. M = [3 1 1 1 1 3; 1 5 5 5 5 1; 1 5 6 6 5 1; 1 5 6 6 5 1; 1 5 5 5 5 1; 3 1 1 1 1 3];  B. M = [6 6 4 4 6 6; 6 3 3 3 3 6; 4 3 2 2 3 4; 4 3 2 2 3 4; 6 3 3 3 3 6; 6 6 4 4 6 6];  C. M = [1 1 1 1 1 1; 1 3 3 3 3 1; 1 3 6 6 3 1; 1 3 6 6 3 1; 1 3 3 3 3 1; 1 1 1 1 1 1];  D. M = [6 6 6 6 6 6; 6 3 3 3 3 6; 6 3 1 1 3 6; 6 3 1 1 3 6; 6 3 3 3 3 6; 6 6 6 6 6 6];  E. M = [6 6 6 6 6 6; 6 6 3 3 3 6; 6 3 6 1 3 6; 6 3 1 6 3 6; 6 3 3 3 6 6; 6 6 6 6 6 6];  F. M = [6 6 6 6 6 6; 6 3 3 3 6 6; 6 3 1 6 3 6; 6 3 6 1 3 6; 6 6 3 3 3 6; 6 6 6 6 6 6]; 

# 6.

Modify the color matrix C and the matrix values in matrix A in the following program so that when the following commands are entered the image shown is produced.

 clear;clc

A = [1 0 1 0 1;
0 1 0 1 0;
1 0 1 0 1;
0 1 0 1 0;
1 0 1 0 1];

C = [0 0 0;
1 0 0];

colormap(C)

imagesc(A)

axis square