MATLAB: Getting rid of a for loop

forloopsrecursionwhile

If I have my code as
function [value1, value2] = scope(input)
c=1;
x=length(input);
for z=2:x
if z==x
break
elseif input(z-1)>input(z) && input(z)<input(z+1)
value1(c,1)=z;
value2(c,1)=input(z);
c=c+1;
end
end
Is it possible to get rid of the for look so the function runs without loops. Thank you.

Best Answer

value1 = find(input(1:end-2) > input(2:end-1) & input(2:end-1) < input(3:end)) + 1;
value2 = input(value1);