How do I put variable values into a text string for Legend

조회 수: 37 (최근 30일)
Hamid Reza Barzegar
Hamid Reza Barzegar 2017년 2월 5일
댓글: Star Strider 2017년 2월 5일
I want to put the variable as a legend but in form of power of some amount this is the variable
x=-1.1;
then in the result i want to see 10^-1.1
figure
plot(Ratio,Final_1,'k-x','linewidth',2)
grid on
legendInfo = ['SNR target for BER 10^' num2str(x)];
legend(legendInfo,'Location','southeast')
xlabel('Ratio')
ylabel('SNR')
problem i have is this part "'SNR target for BER 10^' num2str(x)" because it is not showing like 10^x

채택된 답변

Star Strider
Star Strider 2017년 2월 5일
Use the sprintf function:
legendInfo = sprintf('SNR target for BER 10^%f', x);
  댓글 수: 5
Hamid Reza Barzegar
Hamid Reza Barzegar 2017년 2월 5일
I found it.
legendInfo = sprintf('SNR target for BER 10^{%0.1f}', (x));
Thanks for your reply.
Star Strider
Star Strider 2017년 2월 5일
My pleasure.
I thought you wanted integers rounded to the next lowest integer. The '%.1f' is the correct option for one decimal-place floating-point precision.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by