function [y, idx] = maxv(x)
%MAXV Maximum value of elements in a vector
%   [y, idx] = maxv(y) returns the maximum value y of the
%   elements in a vector x and the index of y in x.
%
%   idx is the element of the first occurrence of y in x.

y = x(1);
idx = 1;
for i = 2:numel(x)
    xi = x(i);
    if xi > y    % > is needed to get the first occurrence of the max value
        y = xi;
        idx = i;
    end
end


