%function x=local_max(y,n=1) %return indices (in order largest first) of n largest local maximas %(including the global ones, i.e. going down at edges) function x=local_max(y,n) if (nargin<2) n=1; end; [r,c]=size(y); x=zeros(r,n); orig=y; minval=min(y); for i=1:n [val,x(i)]=max(y); for j=x(i):c-1 y(j)=minval; if (orig(j)orig(j)) %next is going up break; end; end; end;