Effacer les filtres
Effacer les filtres

Find "intersection" of data array

4 vues (au cours des 30 derniers jours)
Christian
Christian le 3 Sep 2018
Commenté : Christian le 5 Sep 2018
Hello everybody,
I would like to find the "intersections" of different data arrays. The arrays look similar this:
x=[0 1.2 2.5 3.4 4.6 5.4 6.8 7.3 8.6 9.8 7.1 8.5 9.9 10.1 11.4]
y=[100 90 80 70 65 60 55 50 45 40 40 42 44 52 62]
I would like to cut off the part under the intersection and redefine the data set. So it would be enough to find the two connection points (in this example (8.6;45) and (9.9;44)). Any ideas, how to do this? I have ran out of ideas and really need new ideas/inspiration from you guys!
Cheers, Christian
  6 commentaires
Walter Roberson
Walter Roberson le 4 Sep 2018
What would be the expected result for a case such as
9
13
10
11 12
where the data "doubles back" but does not intersect itself?
Christian
Christian le 4 Sep 2018
@Walter Roberson
all of my data-sets intersect, so I won't face a case as you have described. But thanks to "Stephen Cobeldick" I found a perfect solution for my Problem -> check the answer below!

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 4 Sep 2018
Modifié(e) : Stephen23 le 4 Sep 2018
Download and use selfintersect:
I tried it on your example values:
>> x = [0,1.2,2.5,3.4,4.6,5.4,6.8,7.3,8.6,9.8,7.1,8.5,9.9,10.1,11.4];
>> y = [100,90,80,70,65,60,55,50,45,40,40,42,44,52,62];
>> [~,~,s] = selfintersect(x,y)
s =
9 12
>> xnew = x([1:s(1),1+s(2):end])
xnew =
0.00000 1.20000 2.50000 3.40000 4.60000 5.40000 6.80000 7.30000 8.60000 9.90000 10.10000 11.40000
>> ynew = y([1:s(1),1+s(2):end])
ynew =
100 90 80 70 65 60 55 50 45 44 52 62
>> plot(x,y,'-*',xnew,ynew,'-*')
If you have multiple intersects you will have to use a loop (or some alternative) to process each row of the output matrix s.
  3 commentaires
Stephen23
Stephen23 le 4 Sep 2018
@Christian: I hope that it helps. If you find selfintersects useful, then please also go and give it a rating at the page where you downloaded it from. I am sure that its author will appreciate that.
Christian
Christian le 5 Sep 2018
Done! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB 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