function [values, indices] = peaks(v) maxSoFar = v(1); values = [v(1)]; indices = [1]; for i=2:length(v) if v(i) > maxSoFar maxSoFar = v(i); % insert this new value in vector values % e.g., values = [5 6 7] and my new peak is 8 -> values = [5 6 7 8] values = [values v(i)]; % insert this index in vector indices indices = [indices i]; end end