Write a function that will return the mean of the values in a vector, not including the minimum and maximum values. Assume that the values in the vector are unique
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:14| Question number:4.14
All Answers
total answers (1)
outliers.m
function newmean = outliers(vec)
% Calculates the mean minus the minimum
% and maximum values
% Format of call: outliers(vector)
% Returns mean of vector except largest & smallest
%Find and remove the minimum value
[small, indlow] = min(vec);
vec(indlow) = [];
%Find and remove the maximum value
[large, indhigh] = max(vec);
vec(indhigh) = [];
%Calculate the mean of the rest of the vector
newmean = mean(vec);
end
>> vec = randi([0 50],1,10)
vec =
18 5 39 19 12 20 4 6 48 48
>> ave = mean(vec)
ave =
21.9000
>> outliers(vec)
ans =
20.8750
>>
need an explanation for this answer? contact us directly to get an explanation for this answer