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.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 22일
편집: Azzi Abdelmalek 2013년 10월 22일

0 개 추천

A=[1.23;52;14.356]
fid=fopen('file.txt','w')
fprintf(fid,'%.5f\n',A)
fclose(fid)

추가 답변 (1개)

sixwwwwww
sixwwwwww 2013년 10월 22일

0 개 추천

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!

댓글 수: 1

Andrew
Andrew 2013년 10월 22일
In this paticular situation I needed to print a number to the file, whereas here you are printing a string. The other answer works in my case, thanks for the help though.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2013년 10월 22일

댓글:

2013년 10월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by