Extract data points from a plot corresponding to the plot legend
조회 수: 9 (최근 30일)
이전 댓글 표시
I am trying to determine how to extract the data file from the plot.
Data has to correspond with the correct plot. Please help.
open('ExampleData.fig')
댓글 수: 0
채택된 답변
Les Beckham
2023년 2월 7일
fig = openfig('ExampleData.fig'); % open and get a handle to the figure
% get(fig);
ax = get(fig, 'CurrentAxes'); % get handle to the axis in the figure
% get(ax);
lines = get(ax, 'Children'); % get handles to the lines which are children of the axis
% get(lines(1));
for i = 1:numel(lines) % extract the data from each of the lines
xdata{i} = lines(i).XData;
ydata{i} = lines(i).YData;
names{i} = lines(i).DisplayName;
end
names' % display the names to verify that they are in the right order (per the legend)
% looks like they aren't, create a new index vector to re-arrange them
idx = [6 5 4 3 2 1];
xdata = xdata(idx); % note regular parentheses here
ydata = ydata(idx);
names = names(idx);
names' % display the re-arranged names to verify that they are NOW in the right order (per the legend)
% whos
댓글 수: 0
추가 답변 (1개)
Voss
2023년 2월 7일
Here's one way:
f = openfig('ExampleData.fig');
lines = findall(f,'Type','line')
line_props = cell(1,numel(lines));
for ii = 1:numel(lines)
line_props{ii} = get(lines(ii));
end
line_props = [line_props{:}];
line_props
Now you can use line_props to get whatever information about the lines you need.
For example, to get the XData and YData of the '90°Post Thermal Dec' line:
idx = find(strcmp({line_props.DisplayName},'90°Post Thermal Dec'));
data = [line_props(idx).XData(:) line_props(idx).YData(:)]
댓글 수: 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!