How to extract x, y data values from matlab figure?

 Accepted Answer

Open the figure:
h = findobj(gca,'Type','line')
x=get(h,'Xdata') ;
y=get(h,'Ydata') ;
(x,y) is your required data.

6 Comments

what if you want to extract data of two lines ?
h = findobj(gca,'Type','line')
x1=get(h(1),'Xdata') ;
y1=get(h(1),'Ydata') ;
x2=get(h(2),'Xdata') ;
y2=get(h(2),'Ydata') ;
Hi, how can I extract data andd save as mat file from a figure which has 3 subplots, like this:
let say i have y values and need to find the corresponding location, can we find the unspecified location? As an example on figure i want to find the time of the 68.5 m/s ??

Sign in to comment.

More Answers (2)

If you want to get the values of unknown points from the figure and have to use in code then this could be helpful.
delete 2.fig;
savefig('2.fig');
open('2.fig');
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles t
xdata = get(dataObjs, 'XData');
ydata = get(dataObjs, 'YData');

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Asked:

on 19 Feb 2018

Community Treasure Hunt

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

Start Hunting!