Write a block of matlab code the with a vector named age filled with the following values age=[ 2 23 13 5 -1 79 54 102 12 18 ]. Your code should evaluate each the age of each element and output the appropriate statement for each value. Assume that age < 0 is an Error, otherwise fprintf the correct statements, i.e. 'Child', 'Teen', 'Adult', 'Senior', 'Centurion'. Hint: use a for loop with an if elseif... else statement inside the for loop example output: 2 Child 23 Adult 13 Teen 5 Child -1 Error 79 Senior 54 Adult 102 Centurion 12 Child 18 Adult
Explanation / Answer
age=[ 2 23 13 5 -1 79 54 102 12 18 ] for i=1:10 %10 is size array age if age(i)0& age(i)12& age(i)18& age(i)100) fprintf(' %d Centurion ',age(i)); end end