Contents Previous Next Subchapters

Determining The Number Of Matrix Rows In A File
Syntax nrows(file)
See Also ncols , read , xlread , bread

Description
Returns the number of rows in the specified file, where file is a character row vector. The return value is an integer scalar.

The number of rows is equal to the number of lines except that the ellipsis (...) joins the following line to the current one. The expression rowdim(ncols(file, "byte")) can be used to count the actual number of lines in a file.

Example
You can create a file called temp.dat that contains the text
     pi = 3.14159
     e = 2.71828
by entering
     clear
     file = "temp.dat"
     rmfile(file);
     write(file, "pi = 3.14159")
     write(file, "e = 2.71828")
     close(file)
If you then enter
     nrows("temp.dat")
O-Matrix will respond
     2
because temp.dat has two rows.

The nrows function also counts empty lines. You can create a file called temp.dat that contains the text
     pi = 3.14159

     e = 2.71828
     one = 1
by entering
     clear
     file = "temp.dat"
     rmfile(file);
     write(file, "pi = 3.14159")
     write(file, "")
     write(file, "e = 2.71828")
     write(file, "one = 1")
     close(file)
If you then enter
     nrows("temp.dat")
O-Matrix will respond
     4


If a line contains an ellipsis (...), nrows will not count the following line separately. You can create a file called temp.dat that contains the text
     square root of 2 equals ...
     1.41421
     a separate row
by entering
     clear
     file = "temp.dat"
     rmfile(file);
     write(file, "square root of 2 equals ...")
     write(file, "1.41421")
     write(file, "a separate row")
     close(file)
and you enter
     nrows("temp.dat")
O-Matrix will respond
     2