Ho to find the interception
Show older comments
I have a fitted Guassian plot to which I have plotted yline. Now I am interested to extrac two x- interception points through which my line is passing. I am not able to find any easy way to do it. so any help is appreciable.
code:
clc;close all;clear;
resultsdir = 'results';
Row = dir('cross_section_*.mat');
%Coefficients (with 95% confidence bounds):
a1 = 394.5 ;
b1 = 985.1 ;
c1 = 114.8 ;
a2 = 511.4 ;
b2 = 878.5 ;
c2 = 231.2 ;
a3 = -529.8 ;
b3 = 989.8 ;
c3 = 133.6 ;
xData = zeros(1,1640);
yData = zeros(1,1640);
color = ['r','g','b']
for X = 1:9
Filename = Row(X).name;
dest = fullfile(resultsdir, Filename);
Filedata(X) = load(Filename);
figure()
plot(Filedata(X).x)
[xData, yData] = prepareCurveData( [], Filedata(X).x);
ft = fittype( 'gauss3' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0 -Inf -Inf 0 -Inf -Inf 0];
opts.StartPoint = [446.913 842 37.5821195501848 401.619376603545 761 47.8742720232778 393.885950193204 926 55.7197242033307];
[fitresult, gof] = fit( xData, yData, ft, opts );
figure()
h = plot( fitresult,'k', xData, yData);
set(h,'LineWidth', 2)
title(sprintf('Name:%s , R-Square = %0.4f',Filename,gof.rsquare))
legend( h, 'Experiment', 'fit ', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
ylabel('Intensity values')
xlabel( 'Along X of the CMOS', 'Interpreter', 'none' );
grid on
f = fitresult.a1*exp(-((xData-fitresult.b1)/fitresult.c1).^2) + fitresult.a2*exp(-((xData-fitresult.b2)/fitresult.c2).^2) + fitresult.a3*exp(-((xData-fitresult.b3)/fitresult.c3).^2);
Max(X) = max(f)
exp_perc(X) = Max(X)/exp(2);
yline(exp_perc(X))
% Max(X) = max(fitresult.val)
% f = a1*exp(-((Filedata(X)-b1)/c1).^2) + a2*exp(-((Filedata(X)-b2)/c2).^2) + a3*exp(-((Filedata(X)-b3)/c3).^2);
end
plot:

Accepted Answer
More Answers (1)
KSSV
on 23 Jun 2022
1 vote
The best you can use is: https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections
1 Comment
Navaneeth Tejasvi Mysore Nagendra
on 23 Jun 2022
Categories
Find more on Smoothing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!