Fitting function to ecdf plot

5 views (last 30 days)
Hi
I am looking for a way to fit function g to the ecdf-plot I produce as follows.
T = 1000;
cens = (y>T);
ecdf(y,'Function','survivor', ...
'Censoring',cens,'Bounds','on');
g=fittype('a-b*exp(-c*x)');
I would like to use the bounds determined in ecdf as a weighting factor "w" for the fit.
I tried
h=gcf;
dataObjs = findobj(gcf,'-property','YData');
dmy3=dataObjs.XData;
x=dmy3';
dmy4=dataObjs.YData;
y2=dmy4';
g=fittype('a-b*exp(-c*x)');
f=fit(x,y2,g,'StartPoint',[[ones(size(x)), -exp(-x)]\y2; 1]);
hold on;
Though this is giving me the upper bounds as xData and yData.
Thanks in advance for any suggestion.
Peter

Accepted Answer

Peter Mühlenbrock
Peter Mühlenbrock on 24 Mar 2020
Iw ill close this, as I found a solution.
%----access all xy data-----
d = findall(gcf, '-property', 'xdata');
xydatas = arrayfun(@(h) get(h, {'xdata','ydata', 'type'}), d, 'Uniform', 0);
%----adress xy data-----
x1=xydatas{3, 1}{1, 1}' ;
y1=xydatas{3, 1}{1, 2}' ;
w=xydatas{3, 1}{1, 2}'-xydatas{2, 1}{1, 2}';
g=fittype('a*exp(-b*x)+c');
f=fit(x1,y1,g,'StartPoint',[1, 0.02, 0.5],'Weight',w);
hold on;
plot(f)

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!