I'm trying to write a code to implement a cellular automata model in MATLAB and I'm having difficulty at the boundaries. I am attempting to use cylindrical boundary conditions, so the top and bottom row activate one another whilst the left and right edges only activate two along the same edge and the one adjacent to it. I've tried using if statements for the final and first rows and columns and I've also tried to think of a way of using the mod function to loop back around for the cylindrical edge. Does anyone know a way of fixing this sort of problem?