Let N=tile number, R=row number of the tile, C=column number of the tile. nR=number of rows, nC=number of columns. The matrix contains nR*nC tiles. The tiles are numbered from 1 to nR*nC from left to right on each row.
N-1=nC(R-1)+C-1 relates N, nC and R. Note that nR is absent. The reason for the -1's is that numbering starts from 1 rather than zero. The algorithms for calculating R and C need to cater for N>nR*nC; if this happens R and C could be returned as zero; similarly if N is negative or zero.
To find R, divide N-1 by nC to give a quotient and remainder. Add 1 to the quotient to get R and add 1 to the remainder to get C.
Take the 3*3 matrix. nC=nR=3, nC*nR=9. N must be between 1 and 9. Let N=5, so N-1=4. Divide 4 by 3 to give 1 remainder 1. So R=1+1=2 and C=2. Take a 7*5 matrix, nR=7 and nC=5. Let N=21, N-1=20. (N-1)/5=4 rem 0. So R=5 and C=1. But if nR=5 and nC=7 and N=21, we have 20/7=2 rem 6, so R=3 and C=7.