Borrar filtros
Borrar filtros

How to determine the x intercept between a function and a yline?

3 visualizaciones (últimos 30 días)
parslee
parslee el 21 de Ag. de 2022
Respondida: dpb el 21 de Ag. de 2022
I have a Gaussian function and a yline on my plot and I want to determine the intercept of these two lines.
xfit = linspace(-0.85,-0.1,1000);
coeffsx = [-49.2166 -0.3900 0.1389];
LSFfit_x = coeffsx(1) * exp(-((xfit-coeffsx(2))./coeffsx(3)).^2);
HM_x = -24.6082;
figure(1)
hold on
plot(xfit,LSFfit_x)
yline(HM_x)
I tried using interp1, but it only returns one value instead of two.
And it's not the correct value because based on the plot, the intercepts occur at -0.5 and -0.3.
intercept = interp1(LSFfit_x,xfit,HM_x)
intercept = -0.3751

Respuesta aceptada

dpb
dpb el 21 de Ag. de 2022
You've got to have the two separate pieces of the double-valued function for interp1 to work --
>> [mnX,imnX]=min(LSFfit_x);
>> interp1(LSFfit_x(1:imnX),xfit(1:imnX),HM_x)
ans =
-0.505642378767100
>> interp1(LSFfit_x(imnX:end),xfit(imnX:end),HM_x)
ans =
-0.274357652799088
>>

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by