How to determine the number of iteration steps upon using "nlinfit"

Upon using "nlinfit" for nonlinear regression of experimental data I want to control the quality of the iteration process by checking the number of steps necessary to reach the solution, in the same way as it is possible in "lsqnonlin". There is no information about that in the documentation.

 Accepted Answer

One conceptually simple solution is to define your own OutputFcn and specify this in the options structure. This function gets called after each iteration, and your function can simply collect this data (for which persistent is very useful).
The basic idea is that you can write a function that collects whatever data that nlinfit provides when it calls the OutputFcn on every iteration. In practice you would have to do a bit of snooping around first, e.g. locate and read the inbuilt OutputFcn's to see how they process the data, what inputs the output function is called with, etc. The inbuilt OutputFcn is described here:
I have written my own output functions for the ODE solvers, and it makes it a breeze to collect information during the solver process. There is absolutely no need to mess around with diary, and worry about space characters and the like: get the data you want directly from the source!
To get started you should start with something like this:
function myOut(varargin)
varargin{:}
end
and then add persistent, etc.

1 Comment

Good news and thank you again.
A simple workaround that I make use of meanwhile is:
- run "lsqnonlin" in addition; in this function the number of iteration steps is easily available from "output.iterations"
- print out "output.iterations" hoping that there is not so much difference in this regard between "nlinfit" and "lsqnonlin".

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!