Matlab Write a function that repeatedly asks the user to enter an array and disp
ID: 3669794 • Letter: M
Question
Matlab
Write a function that repeatedly asks the user to enter an array and displays a formatted message showing which values are above the mean and which values are below the mean. Create a subfunction within your main function that receives an array, computes the mean, and displays the messages. The subfunction should not return any values. Note that the values in an array can be printed using the “fprintf” function without using a loop (example: fprintf('%d is in the array. ',array). Allow the user to quit by pressing ENTER. Hint: pressing enter actually enters an empty array, so continue looping as long as the array has a nonzero length. The following is an example of what your output might look like:
>> findAboveAndBelowLoop Enter an array (ENTER to quit): [10 20 18 15]
20 is above the mean.
18 is above the mean.
10 is below the mean.
15 is below the mean.
Enter an array (ENTER to quit): [1 2 3 4 5]
4 is above the mean.
5 is above the mean.
1 is below the mean.
2 is below the mean.
Enter an array (ENTER to quit): (user presses the ENTER key)
Explanation / Answer
A = input('Enter an array (ENTER to quit):');
l=length(A)
m=mean(A)
i=0;
while(l>0)
if(A(i)>m)
fprintf("%d is above the mean.",A(i));
else
fprintf("%d is above the mean.",A(i));
end
end