Convertting Text on a plot To a legend (or manually position them) - but using handles

1 回表示 (過去 30 日間)
Jason
Jason 2020 年 2 月 13 日
回答済み: Jason 2020 年 2 月 13 日
Hello.
I have a plot that I have added text to as below.
I am wanting to have as an option, the ability to reposition these text objects to e.g. the top left (or even as a legend).
I have tried this:
htext=findobj(app.UIAxes,'Type','text') % Get text objects
n=numel(htext) % Get number of them
htext2=htext; % get a duplicate so can delete the ones on the plot
delete(htext) % Delete the ones on the plot
for i=1:n %Try to reposition
h=htext2(i)
h.Position=[0.02 60000]
end
So Im getting Invalid or deleted object.
Also, surely ther eis an easier way if I have the handles of all the text objects to e.g. convert ovr to a legend?
Thanks
Jason

採用された回答

Jason
Jason 2020 年 2 月 13 日
Done it.
htext=findobj(app.UIAxes,'Type','text');
n=numel(htext);
htext(1).Position
mxy=max(ylim(app.UIAxes))
for i=1:n
h=htext(i)
h.Position=[320 (1-i*0.05)*mxy 0]
h.FontSize=14
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by