I have a periodic binary matrix which includes a block of ones. I need to find the boundary between zeros and ones in the matrix. Here is an example:

```
A=[0,1,1,1,0,0,0,1,1;
   0,0,0,0,1,1,1,1,0;
   0,0,0,0,1,1,1,1,0;
   0,0,0,0,1,1,1,1,0;
   0,1,1,1,1,1,1,0,0;
   0,1,1,1,1,1,1,0,0;
   0,1,1,1,0,0,0,0,0;
   0,1,1,1,0,0,0,0,0;
   0,1,1,1,0,0,0,0,0]

```

If the matrix was not periodic, I could use

```
perim=bwperim(A);

```

to find the perimeter. But this does not work perfectly for periodic matrices. I appreciate it if someone can help me with this problem.

EDIT:
a periodic matrix is a matrix that its boundary elements are connected to the boundary elements on the other side of the matrix.