As you can see from my last posts, I will be using matrices a lot. First off what is a matrix ? It is an array of data arranged in a special fashion with each other. A single matrix may have several dimension
A matrix can have any number of dimension but it is impossibly hard to imagine more than 3. But there are applications for them still.
A matrix is created thus:
Dim myMatrix(4, 4) as Integer
This will have created a matrix with two dimensions, each containing 5 elements ( starts at 0 ). Easy isn't it ?
The Method I use
We will then look at this piece of code here:
This is the code to make a simple 5 x 5 matrix and write the column number to the console. Note than I did not generate values inside the matrix, it is still empty. I allowed my program to follow the flow of the matrix and reflect the geometry of the matrix itself.
I use a sweeping technique, I choose each line one by one with the first For Next loop. This will allow me to "plug" myself in a single line. After this I sweep through the columns using another For Next. Then moving unto the next line and repeating.
Couple interesting points here. myMatrix.getLowerBound(0) will take the lowest position of the first dimension ( in this case the dimension 0 ) and will go up from there until he encounters the upper boundary of the dimension. If I wanted to make a 3-dimension matrix I would have written
Dim myMatrix(4, 4, 4) as integer
The output is then:

No comments:
Post a Comment