The formula for location number by successive rows for an $n$ by $m$ matrix is
$f(x,y)=m(x-1)+y$
That is, for example a matrix with $n=3, m=4$ \begin{bmatrix} 1 & 2 & 3 & 4\\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \end{bmatrix}
for example, $f(2,3)=4(2-1)+3=7$
I've found this out just a while ago from trying to not use loops in code to get the same answer, but it's been bothering me why $n$ is not in this formula? Sorry if the question is too simple, i was just curious as to why that is. Is it possible to make this a function of $n$ as well?
The variable $m$ occurs in the formula because it lets you know how many entries are in the previous rows (which you need to know in order to compute the current entry). The variable $n$ does not occur in the formula because you do not need to know the total number of rows, you only need to know what row you're currently on.
If you want $n$ to be in there you can think of $n$ as being in the constraints for the domain of your formula. Your formula is only valid when $1 \leq x \leq n$.