フィルターのクリア

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 Center および File ExchangeLabels and Annotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by