How to display comments in a .dat file?

2 views (last 30 days)
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?

Accepted Answer

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

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!