Contents Previous Next Subchapters

Determining The Number Of Columns In Each Row Of A File
Syntax ncols(filematrix type)
See Also nrows , read , readh

Description
Determines the number of columns of the type specified by matrix type that is in each row of the file specified by file, where both matrix type and file are character row vectors. The valid matrix types are "logical", "char", "byte", "int", "real", "double", and "complex". The return value is an integer column vector with the same number of rows as are in the file. The i-th element of the return value is equal to the number of entries in the i-th row of the file.

Example
You can create a file called temp.dat that contains the text
     1 2 3
     4 5
by entering the following commands
     clear
     file = "temp.dat"
     rmfile(file);
     write(file, "1 2 3")
     write(file, "4 5")
     close(file)
If you then enter
     ncols("temp.dat", "int")
O-Matrix will respond
     {
     3
     2
     }
because temp.dat has three integers in its first row and two in its second row. If you continue by entering
     ncols("temp.dat", "char")
O-Matrix will respond
     {
     5
     3
     }
because temp.dat has five characters in its first row and three in its second row (there is one space between each of the numbers).

Ellipsis
If a line contains an ellipsis (...), ncols will not count the following line separately, (characters from the ellipsis up to and including the next new line are replaced by a single space). You can create a file called temp.dat that contains the text
     1 2 3 ...
     4 5
     6 7 8 ...
     9 10
by entering the following commands
     clear
     file = "temp.dat"
     rmfile(file);
     write(file, "1 2 3 ...")
     write(file, "4 5")
     write(file, "6 7 8 ...")
     write(file, "9 10")
If you then enter
     ncols("temp.dat", "int")
O-Matrix will respond
     {
     5
     5
     }
The matrix type "byte" is the same as "char" but the interpretation of the ellipsis is suppressed. If you continue by entering
     ncols("temp.dat", "byte")
O-Matrix will respond
     {
     9
     3
     9
     4
     }