how to avoid the decimal values in fprintf

4 ビュー (過去 30 日間)
jaah navi
jaah navi 2019 年 2 月 7 日
コメント済み: jaah navi 2019 年 2 月 7 日
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 日
Use %d instead of %5.4f
  3 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 7 日
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by