options = optimset('MaxIter',20);
fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
x = fminsearch(fun,x0,options)
Exiting: Maximum number of iterations has been exceeded
- increase MaxIter option.
Current function value: 2.002182
lastwarn
ans =
0×0 empty
char array
options = optimset('Display','final','MaxIter',20);
[x,~,~,s] = fminsearch(fun,x0,options);
Exiting: Maximum number of iterations has been exceeded
- increase MaxIter option.
Current function value: 2.002182
options = optimset('Display','none','MaxIter',20);
[x,~,e,s] = fminsearch(fun,x0,options);
warning('off') doesn't work because the message isn't a warning; it's a normal informative output message.
As the above shows, the only way to suppress it is to turn output off entirely and then retrieve the result from the output variable. The exit flag variable, e will be 0 if this is the cause or the message content itself is a member of the output struct, s