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?
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Daniel LaCroix
2016-1-4
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!