フィルターのクリア

How can I write the value of the array as an exponent in sprintf

13 ビュー (過去 30 日間)
Jan-Erik
Jan-Erik 2011 年 6 月 29 日
Hello, I want write the following function in the legend of my graph: f(x) = a * x^n.
I calculated a and n. Now I want to replace a and n with the corresponding value and write it as a string. So I want to use the command sprintf:
sprintf('\\rm{f(x) = %0.4g * x^%0.3g}', a, n)
The only problem is that I can't get the value for n as an exponent. How can you do that? Is it possible with sprintf?
Thank you for any help!

採用された回答

Matt Fig
Matt Fig 2011 年 6 月 29 日
Works here:
plot(1:10)
legend(sprintf('f(x) = %0.4g * x^%0.3g', .3, 3))
EDIT In response to comments.
In that case:
legend(sprintf('f(x) = %0.4g * x^{%0.3g}', -.3, -3))
  3 件のコメント
Matt Fig
Matt Fig 2011 年 6 月 29 日
See my edit.
Jan-Erik
Jan-Erik 2011 年 6 月 30 日
Works perfectly. Thank you so much!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by