Contents Previous Next Subchapters

Reading A Matrix Of Specified Size From A File
Syntax read(filemtypenrnc)
See Also read(file, mtype) , read(file, mtype, nr)

Description Reads values from the specified file and returns a matrix of the specified type and dimension. The arguments file and mtype have the same meaning as in read(file, mtype) . The integer scalars nr and nc specify the dimension of the return value.

The first row of the resulting matrix corresponds to the first values read, the next row to the next values read, and so on. If there are not enough elements in a row of the file, spaces are used to fill character matrices and zeros are used to fill numeric matrices. If there are more than enough elements in a row of the file, the extra elements are ignored.

You can create a file called temp.dat that contains the text
     (1,2) (3,4) (5,6)
     (7,8) (9,10) (11,12)
by entering the following commands
     file = "temp.dat"
     write(file, "(1,2) (3,4) (5,6)")
     write(file, "(7,8) (9,10) (11,12)")
If you then enter
     read("temp.dat", "complex", 2, 2)
O-Matrix will respond
     [ (1,2) , (3,4) ]
     [ (7,8) , (9,10) ]