Writing zero to text file
8 次查看(过去 30 天)
显示 更早的评论
I am trying to write the number 0 to a text file with a certain amount of precision, ie 0.00000, currently I am using fprintf(fid, num2str(0,6)), which should write the number with 6 decimal places, but it does not work, I was wondering if there is a proper way to do this(other than adding an extremely small offset to the zero) thanks.
0 个评论
采纳的回答
Azzi Abdelmalek
2013-10-22
编辑:Azzi Abdelmalek
2013-10-22
A=[1.23;52;14.356]
fid=fopen('file.txt','w')
fprintf(fid,'%.5f\n',A)
fclose(fid)
0 个评论
更多回答(1 个)
sixwwwwww
2013-10-22
Dear Andrew, you can write the 0s in the text file in the following way:
a = {'0.00000', '0.00000', '0.000000'};
ID = fopen('filename.txt', 'w');
fprintf(ID, '%s\n', a{:});
fclose(ID)
I hope it helps. Good luck!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!