Find out the intersection of two curves despite NaN-Values

1 vue (au cours des 30 derniers jours)
Benedikt Friedrich Nowak
Benedikt Friedrich Nowak le 8 Nov 2022
Hello there,
im struggeling with a the intersection of two curves. One curve is defined as a function :
x= (0 : 50)
y=(m*x)+yaxis (m and yaxis are constants).
The other curves is defined as a dataset of two vectors. Lets say:
V1=[1 2 3 4 5] and V2=[50 80 NaN 90 100].
Right now im using polyxpoly, but it struggels with the NaN-Value:
[xi,yi] = polyxpoly(V1,V2,x,y)
xi and yi would be the intersection.
Does anyone have a better alternative ?
Thank you for your help, Ben !

Réponse acceptée

Jan
Jan le 8 Nov 2022
Modifié(e) : Jan le 8 Nov 2022
x = 0:50;
m = 0.234;
yaxis = 60;
y = (m*x)+yaxis;
V1 = [1 2 3 4 5];
V2 = [50 80 NaN 90 100];
V1(isnan(V2)) = nan; % Avoid error message from polyxpoly
[xi,yi] = polyxpoly(V1,V2,x,y)
xi = 1.3438
yi = 60.3145
plot(x, y);
hold('on');
plot(V1, V2);
plot(xi, yi, 'ok')
I'm not sure what "it struggels with the NaN-Value" means. Without setting the x-value to NaN at locations, where the y-value is NaN, polyxpoly throghs an error. But with a cleaning the code runs fine. So what exactly is the problem?

Plus de réponses (0)

Catégories

En savoir plus sur Images 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!

Translated by