title: How to compare a matrix element with its neighbours without using a loop in MATLAB?
body: <p>I have a matrix in MATLAB. I want to check the 4-connected neighbours (left, right, top, bottom) for every element. If the current element is less than any of the neighbours then we set it to zero otherwise it will keep its value. It can easily be done with loop, but it is very expensive as I have thousands of these matrices.</p>
  
  <p>You might recognize it as nonmaxima suppression after edge detection.</p>