get xlabel,ylabel,title from premade plots

12 ビュー (過去 30 日間)
Ethan Leonard
Ethan Leonard 2022 年 5 月 13 日
コメント済み: Ethan Leonard 2022 年 5 月 13 日
I know I can get these values from regular plots I make, either with a plot handle or with get(get(gca,'property'),'String'), like this:
plot(1:10)
xlabel('x label that I wrote')
get(get(gca,'XLabel'),'String')
ans = 'x label that I wrote'
However, I can't seem to do that for "premade" plots, ones that MATLAB makes automatically. For example, it doesn't work for rlocus and lsim. I'll show that here:
H=tf([1],[1 1])
H = 1 ----- s + 1 Continuous-time transfer function.
rlocus(H)
get(get(gca,'XLabel'),'String')
ans = 0×0 empty char array
While it's true that I can access it from the plotting window and change the labels manually, I hope there's a more efficient way to do it. (I'm trying to change the color of the labels.)
Any help would be super appreciated. Upvote for reading. You're all pros.

採用された回答

Voss
Voss 2022 年 5 月 13 日
I don't think this will work for every premade plot, but it seems to work for plots created with rlocus
H=tf([1],[1 1]);
rlocus(H);
% apparently there are two axes, and the one you want has
% HandleVisibility set to 'off'.
% use findall to find it:
ax = findall(gcf(),'Type','axes')
ax =
2×1 Axes array: Axes (Root Locus) Axes
set(get(ax(1),'XLabel'),'Color','m')
set(get(ax(1),'YLabel'),'Color','g')
set(get(ax(1),'Title'),'Color','r')
  1 件のコメント
Ethan Leonard
Ethan Leonard 2022 年 5 月 13 日
Amazing. Exactly what I needed.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by