Extract data points from multiple plot in one figure on Matlab
21 ビュー (過去 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!