フィルターのクリア

Need help in understanding fprintf command and its application

1 回表示 (過去 30 日間)
Hussain Hayat
Hussain Hayat 2015 年 7 月 14 日
コメント済み: Star Strider 2015 年 7 月 14 日
fprintf( ’%8sVIII\n’, ’Henry’ )
fprintf( ’%-8sVIII\n’, ’Henry’ )
fprintf( ’%.3sVIII\n’, ’Henry’ )
Can someone help me with this? I cant figure out what the fprintf does. Especially the part before Henry in this. Please explain all three so I can use it properly.

採用された回答

Star Strider
Star Strider 2015 年 7 月 14 日
To begin with, the quote syntax is wrong. This is correct:
fprintf( '%8sVIII\n', 'Henry' )
fprintf( '%-8sVIII\n', 'Henry' )
fprintf( '%.3sVIII\n', 'Henry' )
HenryVIII
Henry VIII
HenVIII
The first one right-justifies ‘Henry’ in the 8-character string field (the default behaviour), the second one left-justifies it (note the minus-sign in front of the 8), and the third one, with a 3-character string field, takes only the first three letters and right-justifies them.
See the documentation on format descriptors in the fprintf documentation for all the details.
  2 件のコメント
Hussain Hayat
Hussain Hayat 2015 年 7 月 14 日
Thankyou so much. This helped!
Star Strider
Star Strider 2015 年 7 月 14 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by