headcount(file_name, header_mark)
Many file-reading functions allow the user to specify a number of header lines to skip before reading in data. To facilitate reading from files with an unknown or varying number of header lines, this function opens a text file, counts the number of lines in the header block (defined by a header mark; default is '#''), and (always!) closes the file. This makes it easy to read in data with a single call.
For example:
raw = importdata(my_csv_file, ',', headcount(my_csv_file, '%'));
reads a csv table, automatically skipping lines starting with '%' in the beginning of the file. (Note: it is true that importdata(my_file) will try to infer delimiters and headers automatically, but it will often fail.)
Citar como
Naor Movshovitz (2025). headcount(file_name, header_mark) (https://www.mathworks.com/matlabcentral/fileexchange/48481-headcount-file_name-header_mark), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Compatibilidad con las plataformas
Windows macOS LinuxCategorías
Etiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.