function result = avg(vec)

% Calculates and returns the mean of a vector

mysum = 0;

for i = 1:length(vec)
     mysum = mysum + vec(i);  % increment
end
result = mysum/length(vec);