Fit a sigmoid to my data using MATLAB

有些话、适合烂在心里 提交于 2019-12-10 15:38:01

问题


I have a lot of data, and I think it is possible to fit it to a sigmoid (this thought based on my eye-sight, not a mathematical formula).

How can I find the parametric form with statistically significant explanatory power of the best sigmoid for my data?

Thanks!


回答1:


One great thing that you can do is to use the "Curve fitting" App in Matlab. you can find it in APPS, in "Math, statistics and optimization" section.

over there you can choose your x and y data and the function that you want to fit over them (you can enter custom equations such as sigmoid).

Then you can see the fitting results on a plot, also, fitting parameters are shown.

If you were satisfied with the results and you want to use them inside a code, simply hit the generate code under the File tab. you can see the details in this screenshot i took. after pressing the generate code button, matlab will create a fuction that will give the same result. what i like to do is just copy the parts i need in this case:

 enter code here
 [xData, yData] = prepareCurveData( x, y );

 % Set up fittype and options.
ft = fittype( 'a/(1+exp(-b*x))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.957166948242946 0.485375648722841];

% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );

as you can see matlab adds the necessary details and now you can access fitting parameters using fitresult. for example-> fitresult.a



来源:https://stackoverflow.com/questions/33475519/fit-a-sigmoid-to-my-data-using-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!