필터 지우기
필터 지우기

using fprintf to print same length values

조회 수: 6 (최근 30일)
Ronaldo
Ronaldo 2013년 12월 30일
편집: Daniel 2017년 9월 1일
How can I use fprintf to print values with the same length (the number of digits after the pointer is changing based on the number of digits before the pointer)?
0.00000000
30.0000248
360.000305

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 30일
편집: Azzi Abdelmalek 2013년 12월 30일
b=360.000305
m=9 % fixed length
out=sprintf('%9.9f',b)
ii=numel(strfind(out,'.'))
out=out(1:m+ii)
  댓글 수: 8
Ronaldo
Ronaldo 2013년 12월 31일
Please add the following line (for the sake of completeness). I will accept the answer. Thanks for your great help.
fprintf('%s\n', out);
Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 31일
Ronaldo, I am not adding anything.

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


Daniel
Daniel 2017년 9월 1일
편집: Daniel 2017년 9월 1일
b=360.000305
m=9 % fixed length
out=sprintf('%9.9f',b)
ii=numel(strfind(out,'.'))
out=out(1:m+ii)
% Azzi's got no time for correctness
fprintf('%s\n', out)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by