I would like to find all local minima in an array. For a 2D array M, I would want to find (i,j) such that:
M(i,j)<M(i,j+1)
M(i,j)<M(i,j-1)
M(i,j)<M(i+1,j)
M(i,j)<M(i
-1,j).
I would like to do this in higher dimensions as well. This seems similar to the sort of thing that could be done with the "find" function. I've seen find used for elementwise operations, but I don't know whether it can be used for comparisons that require accessing two elements of the array which is passed in. Is that possible?
While it's easy enough to write loops to do this for 1 or 2 dimensions, it would be nice to have a more general method.