Mat for Beginners: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(Created page with "'''Mat''' (M) is short for '''matrix'''. A matrix is another word for an '''array'''. An array of variables in this case. An array is a series of variables. ==...")
 
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:


each item in the array can contain a different value. for example
each item in the array can contain a different value. for example
:A(1)=10
A(1)=10
:A(2)=30
A(2)=30
:A(3)=25
A(3)=25
:A(4)=40
A(4)=40


one thing you can do with a mat statement is refer to the whole array, so if you said
A mat statement is refer to the whole array, for example:
PRINT MAT A
PRINT MAT A
the system would return
returns the following:
:10
10
:30
30
:25
25
:40
40


another thing you can do with a mat statement is change how large the array is
A mat statement can also be used to change how large the array is, for example:
MAT A(5)
MAT A(5)
would change the array to have 5 items in it.
changes the array to have 5 items in it.
so after executing MAT A(5) if you did
Then, after executing MAT A(5) and typing:
PRINT MAT A
PRINT MAT A
you would get
you would get
:10
10
:30
30
:25
25
:40
40
:0
0


(because the 5th item never got set to anything)
The 5th item was never set to anything, so A(5) returns a 0.


you can also use a mat statement to refer to a range within an array, for example
A mat statement can also refer to a range within an array, for example
PRINT MAT A(2:4)
PRINT MAT A(2:4)
would return
would return
:30
30
:25
25
:40
40


Arrays can be sorted thus changing the order of the items contained within the arrays.
Arrays can be sorted, which changes the order of the items contained within the arrays. For example, to sort an array in ascending order:


also arrays can have more than one dimension.
AIDX(Mat A)
:X(1,1)=5
:X(1,2)=10
:X(2,1)=15
:X(2,2)=20


these are best envisioned like a spread sheet...  having two numbers to identify which cell a value is contained in.
returns
0
10
25
30
40
 
Arrays can also have more than one dimension.
X(1,1)=5
X(1,2)=10
X(2,1)=15
X(2,2)=20
 
These are easiest to picture like a spread sheet with the two numbers identifying which cell a value is contained in (or like X and Y on a graph). Arrays can have up to 9 dimensions.


==See Also==
==See Also==

Latest revision as of 20:44, 23 January 2013

Mat (M) is short for matrix. A matrix is another word for an array. An array of variables in this case. An array is a series of variables.

Examples

Mat A would refer to the whole array of A(1) to A(10) (if 10 is the highest item in the array)

each item in the array can contain a different value. for example

A(1)=10
A(2)=30
A(3)=25
A(4)=40

A mat statement is refer to the whole array, for example:

PRINT MAT A

returns the following:

10
30
25
40

A mat statement can also be used to change how large the array is, for example:

MAT A(5)

changes the array to have 5 items in it. Then, after executing MAT A(5) and typing:

PRINT MAT A

you would get

10
30
25
40
0

The 5th item was never set to anything, so A(5) returns a 0.

A mat statement can also refer to a range within an array, for example

PRINT MAT A(2:4)

would return

30
25
40

Arrays can be sorted, which changes the order of the items contained within the arrays. For example, to sort an array in ascending order:

AIDX(Mat A)

returns

0
10
25
30
40

Arrays can also have more than one dimension.

X(1,1)=5
X(1,2)=10
X(2,1)=15
X(2,2)=20

These are easiest to picture like a spread sheet with the two numbers identifying which cell a value is contained in (or like X and Y on a graph). Arrays can have up to 9 dimensions.

See Also