How to see if the same point is plotted on two different graphs
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2018-4-26
As long as you have the underlying data, I would suggest using that, instead of getting the data from the figures.
采纳的回答
dpb
2018-4-27
编辑:dpb
2018-4-27
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.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!