Extract data points from multiple plot in one figure on Matlab

21 ビュー (過去 30 日間)
Javed Ahmad
Javed Ahmad 2023 年 2 月 1 日
コメント済み: Javed Ahmad 2023 年 2 月 2 日
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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by