% Get the maximum value and its location in a vectoor
clear
x = [5 -1 4 6 -1 -1 0 6 -9];
% Put the first person in the chair. Set location to 1.
xmax = x(1);
locmax = 1;
% Loop over the remaining people. Note that this loop starts at 2 because
% we have already accounted for the first person
for i = 2:length(x)
%
% Compare the next person x(i) with the person in the chair and reset if necessary
if(x(i) >= xmax)
xmax = x(i);
locmax = i;
end
end
disp('Max value')
xmax
disp('Location of maximum')
locmax