Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Main topics: If Statement, User functions, while loop, Find function 1 Fruit Classification Suppose you work for a company that processes fruits. To improve the
Main topics: If Statement, User functions, while loop, Find function 1 Fruit Classification Suppose you work for a company that processes fruits. To improve the efficiency in the shipping process, this company has acquired a new sensor that reads the sourness of four different types of fruits: oranges, pears, grapes, and apples. The sensor then classifies the fruits according to its voltage level as follows: Voltage Level Fruit Name in the Program 5 and 12 Mango (M) 13 and 21 Banana (B) (S) 22 and 33 Strawberry Cherry 34 and 42 (C) 42 Unknown Our goal will be design two functions. The first function will use a while loop to classify the fruit type, while the second function is going to do the same classification, but this time using the find function. 1. In order to test your functions you will have to use the following voltage values for the sourness sensor: volt = [18 33 31 34 15 37 10.5 48 50 38 35 39 42 33 31 1 5 9 13 11 27 35 -1 46 22 6 19 36]; Note(s): Your program should produce output identical (when given the same input(s)) to the sample run(s) below, values and format. 1. Prog6_Drive.m Create a MATLAB Program titled Prog6_Drive.m and open the file. Clear command window and workspace window. Define the voltage matrix as shown in the Sample Run. Call fruitFind function and store the returned array in fruitList. Use while loop and fprintf to display the fruits details as shown in the first tabular table. Call fruit While function and store the returned array in fruitList. Use while loop and fprintf to display the fruits details as shown in the second tabular table. . 2. fruitFind.m Create a MATLAB Program titled fruitFind.m and open the file. Setup a return value called fruitList, and Volts input arguments. Find all the voltage readings between 5 and 12, save it in a variable called V. Save M' on fruitList on the same locations found in variable V. Find all the voltage readings between 13 and 21, save it in a variable called V. Save 'B' on fruitList on the same locations found in variable V. Find all the voltage readings between 22 and 33, save it in a variable called V. Save S'on fruitList on the same locations found in variable V. Find all the voltage readings between 34 and 42, save it in a variable called V. Save 'C' on fruitList on the same locations found in variable V. Find all the voltage readings 42, save it in a variable called V. Save 'U' on fruitList on the same locations found in variable V. 3. fruit While.m Create a MATLAB Program titled fruitWhile.m and open the file. Setup a return value called fruitList, and Volts input arguments. Create new variable called count and initialize it with 1. Setup a new while statement which runs the same number of elements in Volts input arguments, for each iteration do the following checks: o Check the current voltage readings is between 5 and 12, save it in the fruitList variable. o Check the current voltage readings is between 13 and 21, save it in the fruitList variable. o Check the current voltage readings is between 22 and 33, save it in the fruitList variable. o Check the current voltage readings is between 34 and 42, save it in the fruitList variable. o Check the current voltage readings is 42, save it in the fruit List variable. Update the value of count in every iteration. Sample Run: 33 31 34 15 37 volt=[18 10.5 48 50 38 35 39 42 33 31 1 5 9 13 11 27 35 -1 46 22 6 19 36] Output While function Voltage Fruit 18.0 33.0 O 31.0 34.0 15.0 37.0 10.5 48.0 50.0 38.0 35.0 39.0 42.0 33.0 31.0 1.0 5.0 9.0 13.0 11.0 27.0 35.0 -1.0 46.0 22.0 6.0 19.0 36.0 O P U U O O O U O o A A A P P G O U U G A P O Output find function Voltage Fruit P O P U 18.0 33.0 31.0 34.0 15.0 37.0 10.5 48.0 50.0 38.0 35.0 39.0 42.0 33.0 31.0 1.0 5.0 9.0 13.0 11.0 27.0 35.0 -1.0 46.0 22.0 6.0 19.0 36.0 A A A P P G O A P Main topics: If Statement, User functions, while loop, Find function 1 Fruit Classification Suppose you work for a company that processes fruits. To improve the efficiency in the shipping process, this company has acquired a new sensor that reads the sourness of four different types of fruits: oranges, pears, grapes, and apples. The sensor then classifies the fruits according to its voltage level as follows: Voltage Level Fruit Name in the Program 5 and 12 Mango (M) 13 and 21 Banana (B) (S) 22 and 33 Strawberry Cherry 34 and 42 (C) 42 Unknown Our goal will be design two functions. The first function will use a while loop to classify the fruit type, while the second function is going to do the same classification, but this time using the find function. 1. In order to test your functions you will have to use the following voltage values for the sourness sensor: volt = [18 33 31 34 15 37 10.5 48 50 38 35 39 42 33 31 1 5 9 13 11 27 35 -1 46 22 6 19 36]; Note(s): Your program should produce output identical (when given the same input(s)) to the sample run(s) below, values and format. 1. Prog6_Drive.m Create a MATLAB Program titled Prog6_Drive.m and open the file. Clear command window and workspace window. Define the voltage matrix as shown in the Sample Run. Call fruitFind function and store the returned array in fruitList. Use while loop and fprintf to display the fruits details as shown in the first tabular table. Call fruit While function and store the returned array in fruitList. Use while loop and fprintf to display the fruits details as shown in the second tabular table. . 2. fruitFind.m Create a MATLAB Program titled fruitFind.m and open the file. Setup a return value called fruitList, and Volts input arguments. Find all the voltage readings between 5 and 12, save it in a variable called V. Save M' on fruitList on the same locations found in variable V. Find all the voltage readings between 13 and 21, save it in a variable called V. Save 'B' on fruitList on the same locations found in variable V. Find all the voltage readings between 22 and 33, save it in a variable called V. Save S'on fruitList on the same locations found in variable V. Find all the voltage readings between 34 and 42, save it in a variable called V. Save 'C' on fruitList on the same locations found in variable V. Find all the voltage readings 42, save it in a variable called V. Save 'U' on fruitList on the same locations found in variable V. 3. fruit While.m Create a MATLAB Program titled fruitWhile.m and open the file. Setup a return value called fruitList, and Volts input arguments. Create new variable called count and initialize it with 1. Setup a new while statement which runs the same number of elements in Volts input arguments, for each iteration do the following checks: o Check the current voltage readings is between 5 and 12, save it in the fruitList variable. o Check the current voltage readings is between 13 and 21, save it in the fruitList variable. o Check the current voltage readings is between 22 and 33, save it in the fruitList variable. o Check the current voltage readings is between 34 and 42, save it in the fruitList variable. o Check the current voltage readings is 42, save it in the fruit List variable. Update the value of count in every iteration. Sample Run: 33 31 34 15 37 volt=[18 10.5 48 50 38 35 39 42 33 31 1 5 9 13 11 27 35 -1 46 22 6 19 36] Output While function Voltage Fruit 18.0 33.0 O 31.0 34.0 15.0 37.0 10.5 48.0 50.0 38.0 35.0 39.0 42.0 33.0 31.0 1.0 5.0 9.0 13.0 11.0 27.0 35.0 -1.0 46.0 22.0 6.0 19.0 36.0 O P U U O O O U O o A A A P P G O U U G A P O Output find function Voltage Fruit P O P U 18.0 33.0 31.0 34.0 15.0 37.0 10.5 48.0 50.0 38.0 35.0 39.0 42.0 33.0 31.0 1.0 5.0 9.0 13.0 11.0 27.0 35.0 -1.0 46.0 22.0 6.0 19.0 36.0 A A A P P G O A P
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started