필터 지우기
필터 지우기

Need help in understanding fprintf command and its application

조회 수: 2 (최근 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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by