THIS WAS great I spent so much time trying to figure out how to do this. I used it to plot a mesh and then a defined contour plot with however many isolines i want! great job.
This looks like a very useful function, and the feature of interpolated x-positions is cute. Unfortunately, in the 2nd case I tried it on, I found that it misses some extrema and misplaces others. See this example:
y=[-196.7906 -188.8165 -196.5088 -193.5867 -194.6516 -190.3382...
-186.7008 -199.9656 -192.8946 -187.4440 -186.5194 -183.2169...
-201.4095 -198.7111 -189.9841 -195.6190 -189.6214 -188.5710...
-190.1472 -197.9514 -185.7049];
[ma,mi]=findextrema(y);
figure; plot(y); hold on; plot(ma,y(round(ma)),'ro');plot(mi,y(round(mi)),'gs'); hold off