How to display comments in a .dat file?

7 次查看(过去 30 天)
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?

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by