Intersection and maximum value of plots?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I've got multiple plots on one figure, and I need to figure out the point of intersection of only two of the plots, and then the maximum value of another plot?
Just wondering if anyone could give me some help on the code I would need to find this?
Cheers
2 commentaires
Walter Roberson
le 7 Déc 2015
It is easier if you can work with the data values that were used to create the plots, instead of having to extract the data values from the graphics.
Réponses (1)
Arnab Sen
le 28 Déc 2015
From the description I understand that you would like to find out intersection of multiple plots and find maximum of another plot.
If you do not have the access to the vectors which construct the plot, you can get those vectors from 'XData' ,'YData' properties of line structure returned by the 'plot' function. Now note that this vectors are discrete points on the plot and may not contain the actual intersection point. However, we can approximate it by taking those points for which the values of y coordinates are less than a threshold value. Note that more the number of points, more dense the points are, less the threshold and the more approximated values are closer to real intersection points.
Following code snippet illustrates this approach:
>> x = linspace(-2*pi,2*pi,1000);
>> y1 = sin(x);
>> y2 = cos(x);
>> p = plot(x,y1,x,y2);
>> idy1=p(1).YData;
>> idy2=p(2).YData;
%Taking thresold as 10^-2
>> index=find(abs(idy1-idy2)<=10^-2);
%x and y coordinates of the intersection points
>> intersection_X_coordinates=x(index);
>> intersection_y_coordinates=idy1(index);
%Max of plot y2
>> maxy2=max(idy2);
index contains the points for which value of y coordinates of both the plot is differs at most by 10^-2. Here we have taken 1000 points. You can take more points if you need more accuracy. However, if the there are too many points, there is a chance of multiple points close to a single intersection point are given as output by this script.
0 commentaires
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!