Explanation

The code uses the max or min function on the result of find, which is not as fast as using the find options, first and last.


Suggested Action

Remove the call to min or max and pass arguments directly to the find function instead.

For example, replace code such as min(find(A)) with find(A,1).

Similarly, replace max(find(A)) with find(A, 1, 'last').