필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
parslee
parslee 2022년 8월 21일
답변: dpb 2022년 8월 21일
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