|
Contents | Previous | Next | Subchapters |
| Syntax |
headers = read(file, "headers")
|
| See Also | read(file, mtype) , bread(file) |
headers contains N rows where N is the number
of headers at the current line in the file file.
Headers in the input file file must be separated by
spaces or tabs and each header string must not contain spaces or tabs.
The first row of the resulting matrix corresponds to the first header,
the next row to the next header, and so on.
Sample1 Sample2 Sample3
1.1 1.2 1.3
2.1 2.2 2.3
and you enter
clear
file = "temp.dat"
read(file, "headers")
O-Matrix will respond,
Sample1 Sample2 Sample3
If you continue by entering
read(file, "real", 2, 3)
O-Matrix will respond,
{
[ 1.1 , 1.2 , 1.3 ]
[ 2.1 , 2.2 , 2.3 ]
}
The read function can also read text files that contain
multiple header lines at arbitrary lines within the numeric data.
If you have a sample file "headers.dat" that contains,
Test One
Sample1 Sample2 Sample3
1.1 1.2 1.3
2.1 2.2 3.3
Test Two
Sample4 Sample5 Sample6
3.1 3.2 3.3
4.1 4.2 4.3
5.1 5.2 5.3
and you enter,
clear
file = "headers.dat"
read(file,"char",1) # skip descriptive text line
H1 = read(file, "headers") # read first header line
D1 = read(file, "real", 2, 3) # read the 2 lines of data that follow
read(file,"char", 1)
H2 = read(file, "headers") # read next header line
D2 = read(file, "real", 3, 3) # read the 2 lines of data that follow
# print headers and data for 'Test One'
print H1.row(1), H1.row(2), H1.row(3)
print D1
# print headers and data for 'Test Two'
print H2.row(1), H2.row(2), H2.row(3)
print D2
O-Matrix will print,
Sample1 Sample2 Sample3
{
[ 1.1 , 1.2 , 1.3 ]
[ 2.1 , 2.2 , 3.3 ]
}
Sample4 Sample5 Sample6
{
[ 3.1 , 3.2 , 3.3 ]
[ 4.1 , 4.2 , 4.3 ]
[ 5.1 , 5.2 , 5.3 ]
}
The header values can be used for labelling graphs and other O-Matrix
output. If you continue the example above by entering,
gxtitle(H2.row(2))
gplot(D2.col(2))
O-Matrix will create a plot of the second column of data from
'Test Two' in the sample data above, using the corresponding
data header value.