Extract data points from a plot corresponding to the plot legend

20 visualizaciones (últimos 30 días)
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')

Respuesta aceptada

Les Beckham
Les Beckham el 7 de Feb. de 2023
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)
ans = 6×1 cell array
{'0° Pre Thermal Dec' } {'45°Pre Thermal Dec' } {'90°Pre Thermal Dec' } {'90°Post Thermal Dec'} {'45°Post Thermal Dec'} {'0°Post Thermal Dec' }
% 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)
ans = 6×1 cell array
{'0°Post Thermal Dec' } {'45°Post Thermal Dec'} {'90°Post Thermal Dec'} {'90°Pre Thermal Dec' } {'45°Pre Thermal Dec' } {'0° Pre Thermal Dec' }
% whos

Más respuestas (1)

Voss
Voss el 7 de Feb. de 2023
Here's one way:
f = openfig('ExampleData.fig');
lines = findall(f,'Type','line')
lines =
6×1 Line array: Line (0° Pre Thermal Dec) Line (45°Pre Thermal Dec) Line (90°Pre Thermal Dec) Line (90°Post Thermal Dec) Line (45°Post Thermal Dec) Line (0°Post Thermal Dec)
line_props = cell(1,numel(lines));
for ii = 1:numel(lines)
line_props{ii} = get(lines(ii));
end
line_props = [line_props{:}];
line_props
line_props = 1×6 struct array with fields:
XData XDataMode XVariable YData YDataMode YVariable ZData ZDataMode ZVariable XDataSource YDataSource ZDataSource Color ColorMode LineStyle LineStyleMode LineWidth Marker MarkerMode MarkerSize MarkerEdgeColor MarkerFaceColor Clipping MarkerIndices AlignVertexCenters LineJoin Children Parent Visible HandleVisibility ButtonDownFcn ContextMenu BusyAction BeingDeleted Interruptible CreateFcn DeleteFcn Type Tag UserData Selected SelectionHighlight HitTest PickableParts DisplayName Annotation SeriesIndex DataTipTemplate SourceTable
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(:)]
data = 16001×2
12.3436 -0.1052 12.3439 -0.1051 12.3443 -0.1051 12.3447 -0.1051 12.3450 -0.1051 12.3454 -0.1051 12.3457 -0.1051 12.3461 -0.1051 12.3464 -0.1050 12.3468 -0.1050

Community Treasure Hunt

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

Start Hunting!

Translated by