How can I turn off fminsearch's exiting complaints?
21 views (last 30 days)
Show older comments
Jeff Miller
on 17 Jun 2018
Answered: Steven Lord
on 29 Aug 2023
Is there any way to turn off all of fminsearch's complaints to the command window, such as this one:
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: -Inf
I am running fminsearch thousands of times, and I would like to save the exit codes for later processing. These fminsearch messages clutter up the command window, making it hard to see the messages from my own code that I do want to see.
Neither of the following does the job, and I can't find anything else to try:
pctRunOnAll warning off
opts = optimset('Display','off');
Would appreciate any suggestions--thanks.
0 Comments
Accepted Answer
Walter Roberson
on 18 Jun 2018
I just checked the R2018a code for fminsearch. The variable that controls output of the message is set to not print exit messages if 'Display' is set to either 'none' or 'off'
The message IDs used are MATLAB:optimfun:fminsearch:ExitingMaxFunctionEvals MATLAB:optimfun:fminsearch:ExitingMaxIterations However, warning() is not used, so warning('off') cannot turn them off.
Which MATLAB release are you using?
3 Comments
More Answers (1)
Steven Lord
on 29 Aug 2023
Creating an options structure alone is not sufficient to make fminsearch use the modified value of the Display option. It doesn't "change the default Display option" or anything like that. You need to pass that options structure into the fminsearch call as an input argument for that call to use the modified option value.
I'm using one of the examples on the fminsearch documentation page, modified by adding rand so it doesn't converge (and so the default Display option, 'notify', will complain.)
fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2+10*rand;
x0 = [-1.2,1];
opts = optimset('Display', 'off');
Even though I've created opts, this next call doesn't use it so fminsearch displays its message (as per the default value of the Display option, 'notify'.)
[x, ~, exitflag] = fminsearch(fun,x0);
exitflag
This next call does include opts as an input argument, so this call to fminsearch won't display even though it exits in the same way as the previous call.
[y, ~, exitflag] = fminsearch(fun, x0, opts);
exitflag
0 Comments
See Also
Categories
Find more on Startup and Shutdown 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!