newpdv
newpdv

Reputation: 462

Positioning numbers in the matrix

How can I get the position of an element of the matrix as an integer?

In this case, access to information on any arbitrary cell can be arranged on the primary key: id. If used as a key field int_32, it is possible to position matrix [216 x 216] and get square with sides of 65.5 thousand cells.

Upvotes: 0

Views: 50

Answers (1)

Quassnoi
Quassnoi

Reputation: 425753

If you know the matrix size, you can enumerate all cells using, say, (rowNumber - 1) * columns + columnNumber, where columns is the number of columns in the matrix.

To get the rowNumber and columnNumber use this:

rowNumber = ((id - 1) DIV columns) + 1
columnNumber = ((id - 1) MOD columns) + 1

, where DIV and MOD are integer division and modulo operators, respectively.

Upvotes: 1

Related Questions