How can I write the value of the array as an exponent in sprintf
조회 수: 10 (최근 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!
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!