how to avoid the decimal values in fprintf

i want to display "1. particle index is 2"
"2. particle index is 2"
I tried with the followig command
fprintf('%3d. particle index is %5.4f\n',iteration,index)
But is displays "1. particle index is 2.0000"
"2. particle index is 2.0000"
Could anyone help me how to make it to 2 instead of 2.0000

 채택된 답변

madhan ravi
madhan ravi 2019년 2월 7일

0 개 추천

Use %d instead of %5.4f

댓글 수: 3

jaah navi
jaah navi 2019년 2월 7일
편집: madhan ravi 2019년 2월 7일
thanks.
could you please help me to combine the following two fprintf into single command.
code:
particle=index;
fprintf('%3d. global fitness is %5.4f\n',iteration,global_fitness)
fprintf('%3d. global fitness is %d\n',iteration,index)
With respect to the code the two fprintf corresponds to the same iteration .So i want to dispaly the global fitness and index of particle in the same line in command window.
Could you please help me on this.
It's always a good idea to look through the documentation https://www.mathworks.com/help/matlab/ref/fprintf.html if something is unclear. Spend some time that's all it takes.
fprintf('%3d. global fitness is %5.4f and index is %d\n',iteration,global_fitness,index)
jaah navi
jaah navi 2019년 2월 7일
ok.Thanks.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2019년 2월 7일

댓글:

2019년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by