COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Finding the intersection of two data plots

• Follow

```I have two non-linear sets of data A & B which I have plotted against time on the same graph.  Neither A nor B have a common data point at which they intersect, however, when their dots are connected and they are graphed, the lines do intersect.  Is there a command to calculate the values at this point?

Thanks.
```
 0

```On 10-11-18 04:34 PM, Corbin Hedt wrote:
> I have two non-linear sets of data A & B which I have plotted against
> time on the same graph. Neither A nor B have a common data point at
> which they intersect, however, when their dots are connected and they
> are graphed, the lines do intersect. Is there a command to calculate the
> values at this point?

I am not sure if I have understood you correctly. It appears to me that you
are indicating that A and B are finitely-sampled non-linear curves, and that
there is no member of A which is exactly the same as a member of B, but that
when you do linear (!) interpolation between the non-linear points, the linear
interpolations intersect, and you wish to know where ?

If that is the situation, then first you need to interpolate the two on to a
common x (time) base, if they are not already on a common x base. Then, in the
portions of the graph where there is data for both, examine the sign of
(A - InterpolatedB) . The places where the sign of the difference changes
between adjacent entries are the places where there is a point of intersection
somewhere between the entries. Knowing the x (time) and A and InterpolatedB
values on both sides of the intersection, you can use standard "intersection
of two lines" formulae to infer a point of intersection. It probably won't be
an especially *good* inference as you are using linear interpolation on
non-linear data, but it'll be _something_.

If my understanding of what you want to do is not correct, then my fallback
would be to something to do with finding the intersection of the tangent lines
to some point in the curve, but that would not be all that consistent with
```
 0

```Walter Roberson <roberson@hushmail.com> wrote in message <ic4d0d\$4vs\$1@canopus.cc.umanitoba.ca>...
> On 10-11-18 04:34 PM, Corbin Hedt wrote:
> > I have two non-linear sets of data A & B which I have plotted against
> > time on the same graph. Neither A nor B have a common data point at
> > which they intersect, however, when their dots are connected and they
> > are graphed, the lines do intersect. Is there a command to calculate the
> > values at this point?
>
> I am not sure if I have understood you correctly. It appears to me that you
> are indicating that A and B are finitely-sampled non-linear curves, and that
> there is no member of A which is exactly the same as a member of B, but that
> when you do linear (!) interpolation between the non-linear points, the linear
> interpolations intersect, and you wish to know where ?
>
> If that is the situation, then first you need to interpolate the two on to a
> common x (time) base, if they are not already on a common x base. Then, in the
> portions of the graph where there is data for both, examine the sign of
> (A - InterpolatedB) . The places where the sign of the difference changes
> between adjacent entries are the places where there is a point of intersection
> somewhere between the entries. Knowing the x (time) and A and InterpolatedB
> values on both sides of the intersection, you can use standard "intersection
> of two lines" formulae to infer a point of intersection. It probably won't be
> an especially *good* inference as you are using linear interpolation on
> non-linear data, but it'll be _something_.
>
>
> If my understanding of what you want to do is not correct, then my fallback
> would be to something to do with finding the intersection of the tangent lines
> to some point in the curve, but that would not be all that consistent with

You would be correct in your understanding of what I was trying to say.  Are you saying that I should interpolate the two, one-by-one, until I notice a sign change?

The time(x) is common to both A & B sets.  Perhaps I should be more specific with my current program.  It is set to read specific sets of data from an excel sheet (Time, A, B) and that data is then shown graphically.  First A over Time, then B over Time.  A & B are then combined over time on one graph.  I would then like Matlab to simply display the point of intersection and what the (x,y) values of the graph would be.

I hope this helps, thanks again for your time.
```
 0

```On 10-11-18 06:00 PM, Corbin Hedt wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message

>> on to a common x (time) base, if they are not already on a common x
>> base. Then, in the portions of the graph where there is data for both,
>> examine the sign of
>> (A - InterpolatedB) . The places where the sign of the difference
>> changes between adjacent entries are the places where there is a point
>> of intersection somewhere between the entries. Knowing the x (time)
>> and A and InterpolatedB values on both sides of the intersection, you
>> can use standard "intersection of two lines" formulae to infer a point
>> of intersection.

> You would be correct in your understanding of what I was trying to say.
> Are you saying that I should interpolate the two, one-by-one, until I
> notice a sign change?

No need for all that work. You can deduce crossings by looking at

diff(sign(A-B))

Non-zero values of this indicate that a crossing occurred.

Once you have found the index of the crossing, say K, then the lines to find
the intersection of are the segments {t(K), A(K)} to {t(K+1), A(K+1)}, and
{t(K), B(K)} to {t(K+1), B(K+1)}
```
 0

```In article <ic49ks\$h9l\$1@fred.mathworks.com>,
"Corbin Hedt" <corbin.hedt@gmail.com> wrote:

> I have two non-linear sets of data A & B which I have plotted against time on
> the same graph.  Neither A nor B have a common data point at which they
> intersect, however, when their dots are connected and they are graphed, the
> lines do intersect.  Is there a command to calculate the values at this
> point?
>
> Thanks.

<http://www.mathworks.com/matlabcentral/fileexchange/11837>

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
```
 0

```Doug Schwarz <see@sig.for.address.edu> wrote in message <see-052A54.19193318112010@news.frontiernet.net>...
> In article <ic49ks\$h9l\$1@fred.mathworks.com>,
>  "Corbin Hedt" <corbin.hedt@gmail.com> wrote:
>
> > I have two non-linear sets of data A & B which I have plotted against time on
> > the same graph.  Neither A nor B have a common data point at which they
> > intersect, however, when their dots are connected and they are graphed, the
> > lines do intersect.  Is there a command to calculate the values at this
> > point?
> >
> > Thanks.
>
>
> <http://www.mathworks.com/matlabcentral/fileexchange/11837>
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

Thank you Doug,
I will try out your coding and make sure to give proper credit if used.
```
 0

5 Replies
1273 Views

Similiar Articles:

7/20/2012 5:54:22 PM