Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
parslee
parslee le 21 Août 2022
Réponse apportée : dpb le 21 Août 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

Réponse acceptée

dpb
dpb le 21 Août 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
>>

Plus de réponses (0)

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by