How to get legend entries from existing figure ?
38 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am extracting the data from existing figures, this code works for the x, y data, but the Legend variable does not contain any values.
My code:
clear; close all;
addpath(genpath('D:\Uprofily\Blockage\numerika\figures'));
fig1 = openfig("cl_mean.fig");
Legend = findobj(gcf,'Type','Legend')
% data extract
dataObjs1x = findobj(fig1,'-property','Xdata'); % data X
xdata = dataObjs1x(1).XData;
dataObjs2y = findobj(fig1,'-property','Ydata'); % data Y
y1 = dataObjs2y(1).YData; % line y1
y2 = dataObjs2y(2).YData; % line y2
save("cl_mean.mat");
How do I get the legend entries, i.e. the "rect2 Comsol 2d, v=2.8, greatdomain" and some designation which entry belongs to which line ?
Thank you. Petr

0 件のコメント
採用された回答
Matt J
2025 年 12 月 9 日 13:39
編集済み: Matt J
2025 年 12 月 9 日 13:53
The legend's String property will get you the legend labels for the different lines, e.g.,
plot(rand(5,3)); L=legend;
L.String
EDIT: Handles to the original line data can be recovered from,
Hlines = L.PlotChildren
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
