How do I create a tab delimited text file with headers that can be appended every time I run a code I have previously written?
27 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Cyrus Ahmadi
il 4 Gen 2016
Commentato: Cyrus Ahmadi
il 4 Gen 2016
I am trying to write a new script that creates (with headers) and then appends a text file with numbers outputted from variables in another code I have previously written. An example of the output I am looking for would be:
Serial Number Radial Dev RadialOver Ecc TanDev
S001 123 456 78 90
S002 ... ... ... ...
S003 ... ... ... ...
S004 ... ... ... ...
Wherein everytime I call the script, it will add a new line with the values I am calling. Not as familiar with this part of Matlab as I probably should be, any help would be appreciated.
0 Commenti
Risposta accettata
Daniel LaCroix
il 4 Gen 2016
Each time you want to write to a text file, open it with fopen and record the file id MATLAB assigns it. Then use fprintf (hopefully you've used this before) to write to the file, using the file id to tell MATLAB to write to the text file, not the command window. Then close the file to make MATLAB happy.
fid=fopen('stuff.txt','a'); %the 'a' grants append only write access
fprintf(fid,'formatted stuff, use \t for making a table');
fclose(fid);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Low-Level File I/O in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!