How to see if the same point is plotted on two different graphs

1 view (last 30 days)
I am writing a code that results in something if two points on two different plots are the same. I don't know how to write the conditional statement for the if statement. I want it to be something like if (x1,y1) of graph 1 = (x2,y2) of graph 2, show this message. I don't know how to format the names of certain points in the plot. The first plot is made up of many plotted data points, and the second just has one point plotted at any given time. I want to see if that one point ever lines up with the points on the first graph.
  1 Comment
Rik
Rik on 26 Apr 2018
As long as you have the underlying data, I would suggest using that, instead of getting the data from the figures.

Sign in to comment.

Accepted Answer

dpb
dpb on 27 Apr 2018
Edited: dpb on 27 Apr 2018
Rik's point is a good one to use the actual data for the two plots providing it hasn't already been trashed. It's no major deal if it has altho you have to have or be able to get the two figures of interest handles; what that entails depends on whether there are more figures possibly open and all those kinds of details that are unspecified.
Presuming you have those two figure handles as hF1 and hF2 (or array hF(1:2)) then something otoo
hL=findobj(hF1,'type','line'); % get the line handles on that figure
X1=get(hL,'XData');
Y1=get(hL,'YData');
will return cell array of length(hL) each containing double of length(Y) for each line handle.
Obvious to get the value from the other figure given hF2.
After that, use ismember to find the intersection if certain the two will be exact match if are duplicated; otherwise ismembertol may be useful to find near matches that are easily possible in comparing floating point values computed by slightly different means or otherwise that might have gotten rounded slightly differently.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!