I have the following matrix array:
const
xlen = 3
ylen = 4
var
matrix: array[1..ylen, array[1..xlen, int]]
matrix = [
[0,0,0],
[1,3,1],
[0,2,6],
[0,0,3]
]
I would like to create many matrixes and call it like matrix[x]
matrix[1] = [
[0,5,0],
[1,5,1],
[0,2,9],
[0,9,9]
]
matrix[2] = [
[2,2,0],
[1,3,1],
[2,2,6],
[4,0,4]
]
matrix[3] = [
[1,0,0],
[1,3,1],
[0,2,6],
[0,0,2]
]
how do I go about doing this ?
Do you mean something like this?
const
xlen = 3
ylen = 4
zlen = 3
matrix : array[1..zlen, array[1..ylen, array[1..xlen, int]]] =
[[[0,5,0],
[1,5,1],
[0,2,9],
[0,9,9]],
[[2,2,0],
[1,3,1],
[2,2,6],
[4,0,4]],
[[1,0,0],
[1,3,1],
[0,2,6],
[0,0,2]]]
It is rare in most practical applications to require matrices of over 2 dimensions, but here you go. Also, you can do the same in less code if you want to use zero as the first index.