Is there any way to figure out the length of a .dat file (in terms of rows) without loading the file into the workspace?
相关问题
- Extract matrix elements using a vector of column i
- What is the best way to do a search in a large fil
- Spring Integration - Inbound file endpoint. How to
- How do you get R's null and residual deviance
- How to display an image represented by three matri
相关文章
- What is the correct way to declare and use a FILE
- Making new files automatically executable?
- How do I append metadata to an image in Matlab?
- How to serialize data into indented json [duplicat
- How can I write-protect the Matlab language?
- Creating a custom file like object python suggesti
- `std::sin` is wrong in the last bit
- Escape sequence to display apostrophe in MATLAB
It's also worth bearing in mind that you can use your file system's in-built commands, so on linux you could use the command
and then get the number of lines from the returned text (which is stored in
w
). (I don't think there's an equivalent command under Windows.)Row Counter -- only loads one character per row:
or file length (Matlab):
I'm assuming you are working with text files, since you mentioned finding the number of rows. Here's one solution:
This uses FGETS to read each line, counting the number of lines it reads. Note that the data from the file is never saved to the workspace, it is simply used in the conditional check for the while loop.