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
0 个评论
回答(1 个)
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).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!