fprintf table not aligned

12 ビュー (過去 30 日間)
Kalpha.mc
Kalpha.mc 2020 年 10 月 4 日
編集済み: Sindar 2020 年 10 月 4 日
My fprintf table has two numbers off that i can't seem to fix.
Here is my work
table = [r' c' a' s' v'];
fprintf('%5.2f\t%5.3f\t%5.1f\t%5.4f\t%5.3f\n',table')
this is the outcome of my problem
2.50 15.708 19.6 78.5398 65.450
2.89 18.151 26.2 104.8749 100.991
3.28 20.595 33.8 135.0109 147.512
How to make it look like this?
2.50 15.708 19.6 78.5398 65.450
2.89 18.151 26.2 104.8749 100.991
3.28 20.595 33.8 135.0109 147.512

回答 (1 件)

Sindar
Sindar 2020 年 10 月 4 日
編集済み: Sindar 2020 年 10 月 4 日
generally, I suggest not using tabs when you want a table aligned. Instead, set the field widths larger:
fprintf('%6.2f %9.3f %7.1f %10.4f %9.3f\n',table')
I got the specific numbersby trial and error, but there is a formula:
  • first width only needs to fit that data, so assuming that all data is <1000, we have 3 [digits before decimal] + 1 [decimal] + 2 [digits after decimal] = 6
  • remaining fields should also include some padding between columns, so 4 [padding] + 3 [digits before decimal] + 1 [decimal] + 1-4 [digits after decimal] = 8-10

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by