# Multidimensional Matrices

OML supports Multidimensional Matrices.

This is an extension of the 2D matrices (see Collections), where data can be added and extracted across multiple dimensions.

There is no limit to the number of dimensions - the only limit is the size required to store a large, multidimensional matrix.

```
b=ones(2) ==> b is a 2x2 matrix
b(:,:,3) = [5,6;7,8] ==> b is now a 2x2x3 matrix with, in the 3rd dimension the following content :
slice(:, :, 1) =
[Matrix] 2 x 2
1 1
1 1
slice(:, :, 2) =
[Matrix] 2 x 2
0 0
0 0
slice(:, :, 3) =
[Matrix] 2 x 2
5 6
7 8
```

All rules that apply to access elements of a 2D matrix apply to multidimensional matrices.

For example, running this
script:

```
m3m=ones(2,2);
m3m(:,:,2) = [5,6;7,8];
m3m(:)
m3m(:,:,:)
m3m(1)
m3m(:,1,:)
m3m(1,:,2)
```

will produce this
output:

```
ans = [Matrix] 8 x 1
1
1
1
1
5
7
6
8
ans =
slice(:, :, 1) =
[Matrix] 2 x 2
1 1
1 1
slice(:, :, 2) =
[Matrix] 2 x 2
5 6
7 8
ans = 1
ans =
slice(:, :, 1) =
[Matrix] 2 x 1
1
1
slice(:, :, 2) =
[Matrix] 2 x 1
5
7
ans = [Matrix] 1 x 2
5 6
```

Similar to 2D matrices, setting one value of an element defines the size. For
example:

```
m3m(2,2,2)=1
m3m =
slice(:, :, 1) =
[Matrix] 2 x 2
0 0
0 0
slice(:, :, 2) =
[Matrix] 2 x 2
0 0
0 1
```

At this point, few functions support multidimensional matrices (for example, to perform mathematical operations), but data can be extracted from a multidimensional matrix to be used in any of the functions.

A matrix can also be changed to a 2D matrix. For example:

```
b=ones(2,2)
b(:,:,2) = [5,6;7,8];
b ==> here b is a 2x2x2 matrix
b(:,:,2) = [];
b ==> here b is now a 2x2 matrix
```