It looks like you forgot an "any":
"if x(n) > [x(minimo_ind:n-1) x(n+1:massimo_ind)]"
should be
"if any( x(n) > [x(minimo_ind:n-1) x(n+1:massimo_ind)] )"
Also, you could better use the construction
M = NaN(size(x));
for (...)
...
if any(...)
M(n) = x(n);
end
end
M = M(~isnan(M));
which, despite the extra initializations and deletions should be faster (and safer) for long [x] or small [punti], or [x] with lots of local maxima.
Comment only