## How to join two line plots

### Ganesh Nayak (view profile)

on 27 Jun 2019
Latest activity Answered by Jesús Zambrano

### Jesús Zambrano (view profile)

on 2 Aug 2019
Hello,
I have a two point data set. I created two straight line (poly 3) using inbuilt fit curve fitting. (The points in the image are in straight line, but in my data it is more clustered and random. So the curve fit function is used. Please ignore the points).
Since the line is not created using start and end points but through cuve fit function, I have no idea how to extend the line so that the two lines meet at a common point.
what I'm trying to do.
1. Find the extreme points of each line
2. Then find the slope and Y intercept for each line
3. Find intersection point of two lines
4. Draw a polygon passing through 3 points (start point of left line, intersecting point, end point of top line)
for this method I need to find the extreme points of both the lines , which I dont know how. If I get the extreme points, the rest would be pretty straightforward.
Question is-
Is there any alternate method to directly join the two lines ?
if my method is okay and doable, could some one please tell me how I can get the extreme point of a plotted line?
PS: the lines are created using curve fit function. R2019a

### Jesús Zambrano (view profile)

on 2 Aug 2019

Hi Ganesh,
To find the extreme point of a set of points (x1,y1) you could try:
[maxy1, indexy1] = max(y1);
x1(indexy1);
If
x1 = [0 1 2.5 3.6];
y1 = [-4 -3 -2 -1];
then
[maxy1, indexy1] = max(y1);
x1(indexy1);
gives
maxy1 = -1
x1(indexy1) = 3.6
As an alternative method, it might work that you put the two data sets in an (x,y) array and use different interpolation functions. Some of these functions will include oscillations cause they try to match the points with polynomial functions. However, one of these function, pchip, does not oscillate as freely between the sample points.