Extract data points from multiple plot in one figure on Matlab

23 次查看(过去 30 天)
I'm trying to figure out how to extract data points from a figure that has 3 lines plotted on the same graph, and I have no idea how to approach this. I need (x,y) data of each line. Can anyone help me? I have attached my code and figure.
openfig('multiple plots.fig')
h = gcf;
axesObjs = get(h, 'Children');
dataObjs = get(axesObjs, 'Children');
objTypes = get(dataObjs, 'Type');
xdata = get(dataObjs, 'XData');
ydata = get(dataObjs, 'YData');
% extract data
for i = 1:numel(xdata)
fprintf('%d line data\n',i) ;
xdata{i}
ydata{i}
end

回答(1 个)

MarKf
MarKf 2023-2-1
Your figure axes have 3 graphic objects, the first is the green line and the last is the Observed and Simulation ones. In between is the legend. It's the way the figure was created. So in theory you could extract the data programmatically like this:
openfig('multiple plots.fig');
h = gcf;
axesObjs = get(h, 'Children');
dataObjs = get(axesObjs, 'Children');
for i = 1:numel(dataObjs)
objTypes{i} = get(dataObjs{i}, 'Type');
if strcmp(objTypes{i},'line')
xdata{i} = get(dataObjs{i}, 'XData');
ydata{i} = get(dataObjs{i}, 'YData');
end
end
then you end up with data in x/ydata{1} and x/ydata{3}{[1,2]} (x/ydata{2} empty).
  1 个评论
Javed Ahmad
Javed Ahmad 2023-2-2
Thanks for the help Marco Fuscà. Now I am able to extract data points of the two curve (blue and red colour) perfectly. But data points of linear line (green colour) gives a plot which is a scale-up value of what is shown in figure.
Can you help me on this?
I am attaching excel sheet of extracted data points and both the 'charts' for your reference. Chart 1 with all 3 lines and Chart 2 with only curve plots.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by