필터 지우기
필터 지우기

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
Jan-Erik
Jan-Erik 2011년 6월 30일
Works perfectly. Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (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