Using FGETL to skip 2 header lines
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How do I use FGETL to skip 2 header lines?
My data file looks like this
Row 1: ID FName LName Year Class
Row 2: ---------------------------------
Row 3: data starts here
After I open the file with FOPEN
fid=fopen('textfile.dat','r');
How do I use FGETL to skip the 2 header lines (rows 1 & 2)?
Thanks in advance.
0 commentaires
Réponse acceptée
Plus de réponses (1)
Dan Seal
le 27 Juil 2013
A good way to read data from text files with headers is with the textscan function. When calling textscan, you an specify a number of header rows in your file. For example, if ID and Year are numeric and the other columns are strings, use:
fid=fopen('textfile.dat','r');
C = textscan(fid, '%d %s %s %d %s', 'HeaderLines', 2);
0 commentaires
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!