Publication date: 08/13/2020

Note the following when creating matrices:

• Place matrix literals in square brackets. [...]

• Matrix values can contain decimal points, can be positive or negative, and can be in scientific notation.

• Separate items across a column with blank spaces. You can use any number of blank spaces.

• Separate rows with a comma.

For constructing more advanced matrices, see Special Matrices.

Create matrix A with 3 rows and 2 columns:

A = [1 2, 3 4, 5 6];

R is a row vector and C is a column vector:

R = [10 12 14];

C = [11, 13, 15];

B is a 1-by-1 matrix, or a matrix with one row and one column:

`B = [20];`

E is an empty matrix:

E = [];

The following examples show two ways of creating empty matrices:

J( 0,4 );

[](0,4)

[]( 5,0 )

[](5,0)

Specifying the number of rows and columns in an empty matrix is optional. JMP creates the matrix as necessary. For example, the following script defines an empty matrix, iterates over each row in the data table, and returns the heights and weights in a matrix.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

data = []( 0, 2 );

`For Each Row( data |/= Matrix( {{dt:height, dt:weight}} ) );`

`Show( data );`

data = [59 95, 61 123, 55 74,...]

A script can return an empty matrix. In Big Class.jmp, the following expression looks for rows in which age equals 8, finds none, and returns an empty matrix:

a = dt << Get Rows Where( age == 8 );

`Show( a );`

a = [](0,1);

If you want to convert lists into a matrix, use the Matrix() function. A single list is converted into a column vector. Two or more lists are converted into rows.

Create a column vector from a single list:

A = Matrix( {1, 2, 3} );

[1,2,3]

Create a matrix from a list of lists. Each list is a row in the matrix.

A = Matrix( {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} );

[1 2 3,

4 5 6,

7 8 9]

To construct matrices from expressions, use Matrix(). Elements must be expressions that resolve to numbers.

A = Matrix( {4 * 5, 8 ^ 2, Sqrt( 9 )} );

[20, 64, 3]

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).

.