How to display comments in a .dat file?

7 visualizzazioni (ultimi 30 giorni)
aneps
aneps il 7 Set 2017
Risposto: Guillaume il 7 Set 2017
I save my experimental data in a .dat file. The first 5 lines is just text and some blank lines. The text has important information about the data. I use the following code to open the data in matlab for analysis:
filename = [Name,'.dat'];
[fid, message] = fopen(filename, 'rt');
MyData = cell2mat( textscan(fid, '%f%f%f%f%f%f', 'Delimiter', '\t','headerlines',NL) );
fclose(fid);
'MyData' skips the header lines (up to NL=5). I want to display in the Command Window the comments upto line =NL. How can I do that?

Risposta accettata

Guillaume
Guillaume il 7 Set 2017
Just read the first NL lines and display them
%...
[fid, message] = fopen(filename, 'rt');
for row = 1:NL
fprintf(fgets(fid));
end
MyData = cell2mat( textscan(fid, '%f%f%f%f%f%f', 'Delimiter', '\t','headerlines',NL) );
%...

Più risposte (0)

Categorie

Scopri di più su Data Import and Export in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by