Q:

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

0

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. It is okay to use the built-in mean function. To test this, create a vector of 10 random integers, each in the range from 0 to 50, and pass this vector to the function. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now