フィルターのクリア

help about fprintf ( 'x = % f / n', x)

49 ビュー (過去 30 日間)
Nikola
Nikola 2014 年 12 月 22 日
回答済み: Nikola 2014 年 12 月 23 日
I dont understand meaning of (x = %f/n',x), Whats point/meaning in x = %f in help i can only find that /n represent new line, but whats x=%f for?

採用された回答

dpb
dpb 2014 年 12 月 22 日
Try setting
x=pi;
and then the above line at the command line and see...
Also, under the doc for formatting strings under the formatspec link is the following section towards the end --
"The string can also include combinations of the following: ..."
Read that portion carefully.

その他の回答 (2 件)

Image Analyst
Image Analyst 2014 年 12 月 22 日
The "x = " just gets prints as-is. It's nothing special and any characters like that, that aren't preceded with a \ or a % just go down exactly as you put them. The % means it's going to replace that part of the string with a variable. The f means a floating point variable. An s means a string, and a d means an integer. So %f means it's going to replace the %f with the value of x, out to 6 or 7 decimal places, because x is the variable that shows up after the 'x = %f\n' formatting string. If you wanted a specific number of decimal places you could use %.3f to have 3 decimal places. If you wanted to pad spaces on the right to make the whole field, say, 20 characters wide, then you could use %20.3f which would put 3 decimal places to the right of the decimal point, however many digits it needs to the left of the decimal point, and then pad as many spaces on the left as it takes to make the whole thing 20 characters wide.

Nikola
Nikola 2014 年 12 月 23 日
thank you very much

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by