# Matrix (or multiple dimensional array)

Matrixes (sometimes called 2D or multidimensional arrays) are containers for many values. For example, a tic tac toe board is a 2D matrix of 3 rows and 3 columns, each holding a character (usually 'x', 'o', and ' '). Matrixes have all the same properties as Arrays and are indexed in the same manner, just using multiple "indexes", one for each row, column, etc.

# Matrix

For general information on arrays see Arrays.

Matrixes are often 2D arrays. They can be 3D, 4D, or N-D where N is any positive number.

Matrixes are used where ever it is appropriate to put information in tables where the information can be "indexed" by both a row and a column (in 2D).

In Matlab, Matrixes are indexed from 1 (just like arrays). In C, Java, and Actionscript, Matrixes are indexed from 0.

Matrixes are almost always associated with Nested Loops. Nested loops represent placing one loop inside of another. In the case of a 2D matrix, we would have an outer loop (for i = 1 to the number of rows) and an inner loop (for j = 1 to the number of columns).

Here is a sample (in Matlab) of creating a "multiplication table". The matrix represents the multiplication charts. Each "bucket" in the matrix holds the row times the column.

In Matlab, we access a matrix by using () and commas between the row,col,etc. For example multiplication_chart(5,10) = 50;

```	```
for row_index = 1:10
for col_index = 1:10
multiplication_chart(row_index, col_index) = row_index * col_index;
end
end

>> multiplication_chart

multiplication_chart =

1     2     3     4     5     6     7     8     9    10
2     4     6     8    10    12    14    16    18    20
3     6     9    12    15    18    21    24    27    30
4     8    12    16    20    24    28    32    36    40
5    10    15    20    25    30    35    40    45    50
6    12    18    24    30    36    42    48    54    60
7    14    21    28    35    42    49    56    63    70
8    16    24    32    40    48    56    64    72    80
9    18    27    36    45    54    63    72    81    90
10    20    30    40    50    60    70    80    90   100
```
```

In C, Java, and Actionscript, we access a matrix by using one set of []s per dimension. For example multiplication_chart[4][9] = 50; Notice how in these languages, we index from 0!