How to find intersection for two lines composed of multiple points (no expression)

5 views (last 30 days)
Hi, my line1 (x1, y1) and line2 (x2, y2) are plotted using a series of points. And I don't know the exact experssion for these two lines. Now I try to use plotxploy() to find the intersection points between these two lines. And the output is obviously incorrect.
This is my plots, and it is obviously there are two intersection points, one is around (x=3.5, y=0), the other belongs to (x=[4.5-5], y=0.0032)
My code is:
[x,y] = polyxpoly(x1, y1, x2, y2)
And the output for x and y are shown below.
x
3.50228742639397
4.29769427712936
y
1.99387360906001e-06
0.000393524998775350
The first intersection point is correct, but the second one is incorrect. Why this happens?
I would be very appreciated if anyone could give me some help! I also attach my original dataset for line1 and line2 for your reference.
x1 = x2:
2
2.50000000000000
3
3.50000000000000
4
4.50000000000000
5
5.50000000000000
6
6.50000000000000
7
7.50000000000000
8
8.50000000000000
9
9.50000000000000
10
10.5000000000000
11
11.5000000000000
12
12.5000000000000
13
13.5000000000000
14
14.5000000000000
15
15.5000000000000
16
16.5000000000000
17
17.5000000000000
18
18.5000000000000
19
19.5000000000000
20
21
22
23
24
25
26
27
28
29
30
y1:
1.76131111147937e-07
4.10150137696168e-07
8.98606628327289e-07
1.98118766758759e-06
4.75416027686151e-06
0.000657724116984407
0.00676846742869083
0.00466828943276941
0.00322657083628402
0.00210437707632098
0.000727220469261824
9.00031130517465e-05
1.65300328847414e-05
7.02901120234368e-06
5.43944880875311e-06
4.42948916083866e-06
3.73521546467850e-06
3.23301572175158e-06
2.85039560585925e-06
2.55052951486024e-06
2.31152992650156e-06
2.11462065544137e-06
1.95024238690200e-06
1.81094584690620e-06
1.69125674414394e-06
1.65452664591159e-06
1.55979294387681e-06
1.47606740206982e-06
1.40151411470039e-06
1.33467340284858e-06
1.27439298988421e-06
1.21972616247566e-06
1.16990630596086e-06
1.12430436551870e-06
1.08239046078176e-06
1.04372092107722e-06
1.00792583558166e-06
9.43849418063191e-07
8.88146435772954e-07
8.38985934978720e-07
7.95232328025381e-07
7.56023629261176e-07
7.20701380916484e-07
6.88668724265897e-07
6.59545586670600e-07
6.32897074527897e-07
6.08425697829140e-07
y2:
7.39203804496990e-20
2.18629541964055e-20
2.70267039750480e-20
4.75334886808465e-20
0.000435833392129257
0.000364773253248048
0.000245653200904618
0.000139887514716788
6.51792912209057e-05
2.43448692525336e-05
7.40640439291876e-06
1.98305137947476e-06
5.61720702794341e-07
1.97036222420262e-07
8.60996259397569e-08
1.04648176425091e-14
3.58032436553035e-17
6.09804005010990e-19
4.05206152491998e-20
1.01809708355593e-20
2.32408165017996e-21
1.22384729164586e-20
8.02237022330977e-17
3.58513394693173e-13
3.25226523865012e-09
2.34819038063527e-05
2.91780804502769e-05
3.27972032657198e-05
3.26547511752575e-05
3.80532734446164e-05
4.32907079560054e-05
4.80401597671560e-05
5.23393641723076e-05
4.75336790631206e-05
5.10004879398830e-05
5.43928307190286e-05
5.75078662772507e-05
5.27795845156329e-05
5.78167479098605e-05
5.10996522859206e-05
5.24603527545990e-05
5.79922949531323e-05
4.91852302860333e-05
5.20928520746284e-05
5.51300084833329e-05
5.83183934907676e-05
4.69351292764145e-05
  4 Comments
Dave B
Dave B on 16 Nov 2021
I don't know why what you plot is relevant to where they intersect. If you want to scale down one of the lines, and you want that to affect the intersection points, you should do the scaling on the values rather than using yyaxis...
Ying Wu
Ying Wu on 16 Nov 2021
Thanks! I have plotted them in one y-axis, and I think the figure looks correct now. Thanks for your help!!!

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!