举个例子:x=0:0.01:10;y=sin(x)+cos(x); indmax=find(diff(sign(diff(y)))<0)+1;%极大值点 indmin=find(diff(sign(diff(y)))>0)+1;%极小值点