I am new with matlab, in advance sorry for my question. How can I find the mean of a vector that only takes elements between 15 and 25.
Ex.
I have a vector: v = [20 8 15 19 7 31]
What i want as output for this vector is (20+15+19)/3 = 18.
I know that the equation to use is:
sum(v)/length(v) = mean(v)
but i only want to include elements from 15:25 in any(!) vector.
My question: How can l write a program that computes and returns the mean, taking only the valid measurement (15-25)? This is regarding both vectorization and/loops
So far i have this code:
function averageRate = fermentationRate(vector)averageRate = 0;for k = 1:length(vector) if (vector(k) < 25 && vector(k) > 15) averageRate = (averageRate + vector(k)); endend
That only tells the sum of the vector, i miss the dividing by length(vector). How can l add this?
Best Answer