MATLAB: Finding intersection point between a scatter and vertical lines

intersectionscattervertical lines

Is there any way to find the y values of the intersection points between a scatter and vertical lines?

Best Answer

Use interp1. I had to do a fair amount of coding to get the data from your figure, but since you will have all the original data, you can skip directly to the YIsx = interp1 step:
openfig('figure 10.fig'); % Get figure & extract data
h1c = get(gca, 'Children');
Xdc = get(h1c, 'XData');
DSz = cellfun(@max,(cellfun(@size, Xdc, 'Uni',0))); % Get data sizes
IdxMx = find(DSz == max(DSz));
Xdmx = cell2mat(Xdc(IdxMx));
Xd = cell2mat(Xdc(setdiff(1:length(Xdc),IdxMx))); % X-values of vertical lines
Ydc = get(h1c, 'YData');
Ydmx = cell2mat(Ydc(IdxMx));
% Yd = cell2mat(Ydc);
YIsx = interp1(Xdmx, Ydmx, Xd(:,1)); % Find intersections
hold on
plot(Xd(:,1), YIsx, '+r', 'MarkerSize',10, 'LineWidth',2) % Plot intersections
hold off
produces: