So, the question you are asking is: "How do I tell the network that the values at the same position $(i,j)$ in different examples are related"?
Dontloo is answering the question: "How do I tell the network that values in the same example, at close positions are related, i.e. tell the network that $(i,j)$ is related to $(i-1,j)$, $(i+1,j)$, $(i,j+1)$, etc." For the second question, Dontloo is correct that convolutional neural networks are the way to go. However for the first question, the answer is much simpler: you don't really need to do anything. You just need to make sure that you feed $(i,j)$ into the same neuron of the neural network each time, and then everything works out. So if you vectorize the matrix, you for example need to make sure that you do that consistently row-wise or consistently column-wise and not mix that up. The neural network will then learn how to process each input value, and since each $(i,j)$ is supplied into the same input neuron each time, it will use the patterns it sees in the $(i,j)$ of different examples. So no need to do anything except keeping everything consistent