Effacer les filtres
Effacer les filtres

How to display comments in a .dat file?

7 vues (au cours des 30 derniers jours)
aneps
aneps le 7 Sep 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?

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by