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

3 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2022-8-21
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
>>

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by