First open the figure, then obtain the x and y coordinates of the line with
line = get(gca, 'Children'); % Get the line object in the current axis of the figure.
x = get(line, 'XData'); % Get the abscissas.
y = get(line, 'YData'); % Get the ordinates.
To obtain the value yi
at the point with abscissa greater or equal then xi
you can write
id = find(x>=xi, 1, 'first'); % On the opposite try find(x<=xi, 1, 'last');
yi = y(id);
Or you can do a linear interpolation
yi = interp1(x, y, xi);
To extract the values between the points with abscissa x1
and x2
you can follow both strategies. With the first you could write
ids = find(x>=x1 & x<=x2);
xReduced = x(ids); % A subset of x.
yReduced = y(ids); % A subset of y.
The first line intersects the set of points that follow x1
with the set of points that precede x2
, and the return the indices. If you choose to interpolate tou can construct a new set of points, and interpolate over that set.
xReduced = x1:step:x2; % As an alternative you can use linspace(x1, x2, nPoints);
yReduced = interp1(x, y, xReduced);