Mat for Beginners: Difference between revisions
(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. ==...") |
|||
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(2)=30 | |||
A(3)=25 | |||
A(4)=40 | |||
A mat statement is refer to the whole array, for example: | |||
PRINT MAT A | PRINT MAT A | ||
the | 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) | MAT A(5) | ||
changes the array to have 5 items in it. | |||
Then, after executing MAT A(5) and typing: | |||
PRINT MAT A | PRINT MAT A | ||
you would get | 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) | PRINT MAT A(2:4) | ||
would return | would return | ||
30 | |||
25 | |||
40 | |||
Arrays can be sorted | Arrays can be sorted, which changes the order of the items contained within the arrays. For example, to sort an array of string constants: | ||
AIDX(Mat A$) | |||
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 [[Mat]] for more details. | |||
==See Also== | ==See Also== |
Revision as of 20:42, 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 of string constants:
AIDX(Mat A$)
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 Mat for more details.