Dear Rafaela,
In your code an image is imported, with the size (s1) by (s2) pixels. The first value corresponds to the amount of horizontal pixels. The second value corresponds to the amount of vertical pixels.
In the first for loop, an array is generated, where 8 rows are selected (2, 25, 112 .. etc). In the second loop each column is selected (1, 2, 3, ...) . Therefore by nesting these for loops, a grid is generated, where a calculation can be performed, where the knots of these gridlines can be used for calculation.
In this MATLAB code, the if loop checks if the point on that knot is zero (white). I hope this has helped you.
As a hint: On this Mathworks website, a short tutorial can be found to trace an object in an binary image.
Kind regards, Christiaan