Borrar filtros
Borrar filtros

Find intersection of two guassian curves

2 visualizaciones (últimos 30 días)
Trisha Kibaya
Trisha Kibaya el 11 de Sept. de 2018
Editada: jonas el 12 de Sept. de 2018
Hi all these are my two curves:
y1 = p(1)*pdf(n1,xgrid); hold on; plot (xgrid, y1,'b'); % hold off
y2 = p(2)*pdf(n2,xgrid); hold on; plot (xgrid, y2,'r'); % hold off
I need to find the exact x coordinates where this two lines meet.
I tried using:
index_intersection = find(y1 == y2);
but it gives me index_intersection =
1×0 empty double row vector
I also tried:
idx = find (y1 - y2 < eps, 1);
but still didn't get the right coordinates.
Please, is there another alternative? I read online that I could use fzero, but I haven't understood how to use the syntax. Thanks in advance.
  3 comentarios
jonas
jonas el 11 de Sept. de 2018
Check out InterX on FEX
Trisha Kibaya
Trisha Kibaya el 11 de Sept. de 2018
numComponents=2;
paramEsts = fitgmdist(data(:),numComponents);
p = paramEsts.ComponentProportion;
and p has two values.
p =
0.3915 0.6085

Iniciar sesión para comentar.

Respuesta aceptada

jonas
jonas el 11 de Sept. de 2018
Editada: jonas el 11 de Sept. de 2018
If you have only one intersection, then you can just find the minimum difference
[~,idx] = min(abs(y1 - y2))
This will however always output a value even when there is no intersection. Also, the accuracy depends on the resolution of your x-vector, where higher resolution yields better accuracy (this is true for most methods). I always recommend InterX from FEX for finding intersections. It interpolates your data per default for high accuracy.
  2 comentarios
Trisha Kibaya
Trisha Kibaya el 12 de Sept. de 2018
Please, pardon my ignorance but is FEX another MathWorks product? Cause i don't have that
jonas
jonas el 12 de Sept. de 2018
Editada: jonas el 12 de Sept. de 2018
Sorry, FEX is short for fileexchange where you can find open source user-submitted functions. Follows the link in my answer, download and put it in your matlab search path

Iniciar sesión para comentar.

Más respuestas (1)

KSSV
KSSV el 11 de Sept. de 2018
Editada: KSSV el 11 de Sept. de 2018
tol = 10^-3 ; % Change this if required
idx = abs(y1-y2)<=tol ;
  3 comentarios
KSSV
KSSV el 11 de Sept. de 2018
To compare two flottant numbers it is suggested to subtract check for inequality with tolerance, rather then using ==.
Trisha Kibaya
Trisha Kibaya el 12 de Sept. de 2018
Thanks a lot

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by