





4.4 Assignment  Lecture 4In this assignment you will experiment with conditionals and function mfiles.4.4.1 Part A: Cartman in 2bit colorUsing the discussed example code from the lecture notes as a starting point, modify the conditional of the colorreduction algorithm to include one more "bit" for possible colors. In other words, possible intensity values now include 0, 85, 170, and 255. For example, a black to red gradient in this color space would be grad1=(0,0,0), grad2=(85,0,0), grad3=(170,0,0), grad4=(255,0,0).You will have to partition the existing color space of 0..255 into four portions, and make decisions based on the existing intensity value to transform them into the new space of (0,85,170,255). Note that the four partitions will not be of equal size  intensities reduced to value 0 will come from a space between 0 and X, while intensities reduced to value 85 will NOT come from a space between 85 and Y. In other words, the set of new intensity values (0,85,170,255) act as centers, and values in proximity of those centers will be replaced by the center values. The center of zero will not have any values to the left, because negative values do not exist in the intensity space. The greatest proximity value for center zero is one less than the smallest proximity value for center 85. You should make some decision as to what range of original color values maps to the new color values. Be sure to document the decision in your mfile as comments. You may hardcode the values in your code. You are required to use one sequence of conditionals, including if, elseif's, and else. Display the image after modifying it. 4.4.2 Part B: The Snake revisited (still not a real one)Recall this exercise from the last assignment. You were required to use forloops to fill a matrix with numbers, such that the path of increasing numbers forms a snake. Using several forloops is one way of completing the problem, but it is much more efficient to use conditionals as well. You would use one variable for keeping track of the increasing number. Its value is then placed into the matrix in a nested for loop, where the outer loop iterates over all rows, and the inner loop iterates over columns. The conditional is used to decide which direction the inner loop takes on; whether it goes from left to right, or right to left. The decision is based on whether the row number is odd or even. Implement this method of using a nested forloop and conditionals to make the decision of direction.
Hint: The number of arguments passed, i.e. whether 1 or 2 or more, is assigned to the variable named nargin (number of arguments in). This variable is available within a function  you need not define it yourself. You should use this variable in your if statement to figure out how to compute the area (either circle or ellipse). Hint: The scalar of Π is predefined in Matlab as the variable name pi . 4.4.4 Part D: size representationWrite a function that takes as input one argument: a certain number of unnamed units. The returned value for this function is a formatted string that best represents the numerical value in terms of common size representation (e.g. milli, kilo, Mega, etc.). You will have to decide which quantity is most suitable for the input. For example, if the input to the function is 18000, then a representative value is best described in kilo: 18 Kilo; similarly, 5620000 is 5.62 Mega, 123456789 is 123.45 Mega, 0.00001 is 10 nano, etc. You will have to implement the logic behind deciding how far to simplify (divide or multiply) a number. Because naming convention for units suggests splitting after every 1000, you should have at most 3 nonzero digits before the decimal after any conversion. Below is a table of conversions you are responsible for. The returned value should be a string, which includes the converted numerical value, as well as the abbreviated and nonabbreviated units, e.g. your_function(18000) returns '18 k (kilo)'. You can produce a string that includes a number using the following expression:strcat(num2str(x), ' abbr.unit (full named unit)') where num2str(x) converts number x to a string, and strcat(a,b) concatenates strings a and b.

