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?

12 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Daniel LaCroix
Daniel LaCroix le 4 Jan 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);

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings 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