find line handles related to legend entries
古いコメントを表示
Before R15 I used to be able to find the handle of an object, referred to in the legend of an existing graph by a certain legend string, say "measured" as follows:
hlegend=findobj(gcf,'Type','axes','Tag','legend');
legenddata=get(hlegend,'userdata');
legendstrings=legenddata.lstrings;
ii=find(strcmp('measured', legendstrings));
h_measured=legenddata.handles(ii);
I dont see how to do something similar with the new graphics handles system in R15. Any suggestions?
採用された回答
その他の回答 (1 件)
Brendan Hamm
2015 年 7 月 7 日
The legend will no longer store this information unless you pass it to the UserData. I would suggest returning the objects created by your various graphics commands anytime you will need to access the data later.
f = figure;
ax = axes;
p = plot(randn(100,5)); % Make a plot of some random data
leg = legend('A','B','C','D','E'); % Create legend and return the object
leg.UserData = p; % We could assign the handles to the legend directly
idx = strcmp(leg.String,'B')
B = leg.UserData(idx) % returns the Line object
% We don't really need to store to the UserData.
Balt = p(idx); % Alternative without storage.
カテゴリ
ヘルプ センター および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
