Write a block of matlab code the with a vector named age filled with the followi
ID: 3653463 • Letter: W
Question
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 AdultExplanation / 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 endRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.