Matrix Creation

The simplest way to create a matrix is to type it in at the command line:

> m = [ 1, 2, 3; 4, 5, 6; 7, 8, 9 ]
 m =
        1          2          3  
        4          5          6  
        7          8          9

In this context the `[ ]' signal RLaB  that a matrix should be created. The inputs (or arguments) for matrix creation are whatever is inside the `[ ]'. The rows of the matrix are delimited with `;' and the elements of each row are delimited with `,'.

Users can use most any expression when creating matrix elements. Other matrices, function evaluations, and arithmetic operations are allowed when creating matrix elements. In the next example, we will create a direction cosine matrix using the built-in trigonometric functions within the `[ ]'.

> a = 45*(2*pi)/360
 a =
    0.785
> A = [ cos(a), sin(a); -sin(a), cos(a) ]
 A =
    0.707      0.707  
   -0.707      0.707

Matrices can also be read from disk-files. The functions read, readb and readm can read matrix values from a file. The read function uses a special ASCII text file format, and is capable of reading not only matrices, but strings, and lists as well. Since the file can contain many data objects, and their variable names, read is used like:

> read ( "file.dat" );

The variables are read from file.dat and installed in the global-symbol-table.

The readb function works like read, except it reads binary files for greater efficiency. The binary files created with writeb are portable across computers that use IEEE floating point format.

The readm function reads a text file that contains white-space separated columns of numbers. readm is most often used to read in data created by other programs. Since readm is only capable of reading in one matrix per file, and no variable name information is available, readm is used like:

> a = read ( "a.dat" );