MATLAB: How to display comments in a .dat file

datadata import

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?

Best Answer

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) );
%...