Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to stop nonlinear fitting and obtain the results of fitting at that iteration

Asked by Manuel on 24 Jul 2012

Dear all,

I am doing a non linear fittig of data to a function. It takes a lot of time for each iteration since it involve also action to external file.

As the title says, do you know how to stop nonlinear fitting iteration at certain point, and obtain the results of fitting at that iteration.

Wiht the result I mean like goodness of fitting, confidence interval, jacobian, etc.. etc.. all this thigs that matlab fitting usually provide at the end of the fitting.

I tried to manually stop the fitting with ctrl+break but I lose the above mentioned results.

Thank you very much in advance.

0 Comments

Manuel

Products

4 Answers

Answer by Sargondjani on 24 Jul 2012
Edited by Sargondjani on 24 Jul 2012

im no expert on this (sorry) but did you try the 'output' function thingy... i know for most optimizers there is such a thing. it should be able to get the results of each iteration and put them somewhere i guess.

if you cant find it pls tell me which function you are using, then i can have a look there

0 Comments

Sargondjani
Answer by Star Strider on 24 Jul 2012
Edited by Star Strider on 24 Jul 2012

You probably need to add an ‘options’ structure to your main routine before calling your curve-fit function, to limit the number of function iterations to less than the default. For ‘lsqcurvefit’ this is ‘optimset’, and for ‘nlinfit’ it is ‘statset’. The options you need to add are 'MaxIter', 'MaxFunEvals', or both. To find out what the defaults are, type ‘optimset’ or ‘statset’ at the command line without either input or output arguments (and without the quotes). Then follow the documentation to create your own options structure with the number of iterations or function evaluations you want.

0 Comments

Star Strider
Answer by Manuel on 25 Jul 2012

Dear all,

first of all thank you.

I am using the nlinfit for this calculation.

I tryed to use in the option 'MaxFunEvals', but seems that it is not possible to use it with nlinfit.

I tryed to specify in the option 'Display','iter' but nothing happens.

I tryed to specify in the option 'MaxIter' for istance maximum 2 iteration but still it lunch the function evalutation (which is the one that takes me long time) more than 40 times!

Thank you in advance for any suggestions,

0 Comments

Manuel
Answer by Sargondjani on 25 Jul 2012

the display iter only displays something after an iteration is complete (after all function evaluations of that iteration are done)

i doubt if there is a built in solution to solve this. however, you can get the code of the function 'nlinfit' if you do "type nlinfit" then you can copy-paste the code, adjust it to your needs, and save it as a function nlinfit_2

0 Comments

Sargondjani

Contact us