How to get subscripts in the legend of a Nichols plot?

9 ビュー (過去 30 日間)
Bill Tubbs
Bill Tubbs 2020 年 8 月 28 日
コメント済み: Adam Danz 2020 年 8 月 28 日
How do I put subscripts in a Nichols plot legend?
This works fine in a normal plot:
figure
plot([0 1],[3 4]); hold on
plot([0 1],[4 5])
plot([0 1],[5 6])
legend('G_2', 'G^2', 'G^2_p')
saveas(gcf,'test1.png')
produces:
But:
figure
nichols(Gp); hold on
nichols(Gc1*Gp);
nichols(Gc2*Gp);
legend('G_2', 'G^2', 'G^2_p')
saveas(gcf,'test2.png')
produces:
I tried this:
figure
nichols(Gp); hold on
nichols(Gc1*Gp);
nichols(Gc2*Gp);
legend('$G_2$', '$G^2$', '$\hat{G}^2_{p}$','Interpreter','Latex')
Produces:
Maybe this is the same bug reported in this question in 2015: Subscripts in MATLAB Legends

採用された回答

Adam Danz
Adam Danz 2020 年 8 月 28 日
This is caused by an extra excape character added when the legend is initially created.
Details are explained by these two answers here.
As explained in that link, you can call the legend twice and the second time should fix the problem.
% Demo
H = tf([-4 48 -18 250 600],[1 30 282 525 60]);
nichols(H)
legend('G^2_p')
legend('G^2_p') % <-- intentionally called again
  2 件のコメント
Bill Tubbs
Bill Tubbs 2020 年 8 月 28 日
編集済み: Bill Tubbs 2020 年 8 月 28 日
Thanks.
Indeed you are right:
% First time
h1 = legend('G_2', 'G^2', 'G^2_p')
h1 =
Legend (G\_2, G^2, G^2\_p) with properties:
...
% 2nd time
h2 = legend('G_2', 'G^2', 'G^2_p')
h2 =
Legend (G_2, G^2, G^2_p) with properties:
...
How unusual.
Adam Danz
Adam Danz 2020 年 8 月 28 日
Indeed. The surprises we find in the entrails for Matlab....

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by