How to put a string in a text file to define headers to data?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexandria Will-Cole
am 15 Nov. 2018
Beantwortet: Jeremy Hughes
am 15 Nov. 2018
Here is my code. I'm trying to make a header for columns of data, but everytime I run only the data remains in the file. Please help! Thanks.
for k=1:3
filename1=sprintf('s%d.txt',k);
fprintf(filename1, '# GHz S DB 50');
for j=1:3
M(j,1) = k;
M(j,2) = k;
M(j,3) = k;
dlmwrite(filename1,M,'-append','delimiter','\t');
end
end
2 Kommentare
Bob Thompson
am 15 Nov. 2018
Are you sure the headers are printing in the first place? Typically when I print headers for data I end up needing to open the file with fopen before the headers will print for me.
Akzeptierte Antwort
Jeremy Hughes
am 15 Nov. 2018
The issue is here:
fprintf(filename1, '# GHz S DB 50');
fprintf doesn't accept a file name, it need an open, writable file-id
fid = fopen(filename1,'w');
fprintf(fid, '# GHz S DB 50');
fclose(fid);
Then things should work as you expect
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Export finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!