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

13 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by