How to insert loop variable inside plot label?

I want to insert the value of the loop variable inside a label next to a string. How do I do it?
for i = 1:n
subplot(1,n,i)
plot(1:m,THETA(i,:))
hold on
plot(1:m+1,THETA_est_rls(i,:))
plot(1:m+1,THETA_est_ewrls(i,:))
legend('true','RLS','EWRLS')
xlabel('Iterations');
ylabel('\theta', i);

 채택된 답변

Star Strider
Star Strider 2018년 9월 30일

1 개 추천

I assume you want to include it in your ylabel call.

This works:

ylabel(sprintf('\\theta %d', i));

The double \\ are necessary to get one of them to print correctly. (The leading \ operates as an ‘escape’ character.)

댓글 수: 6

Thanks! Very helpful
As always, my pleasure!
If you want the index ‘i’ to appear as a subscript instead, this works:
ylabel(sprintf('\\theta_{%d}', i));
Ok. What if I want also to put a cap over theta. Do I have to use latex?
For the cap, yes.
ylabel(sprintf('$\\hat{\\theta}_{%d}$', i), 'Interpreter','latex');
Awesome. Thanks again!
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2018년 9월 30일

댓글:

2018년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by