time | calls | line |
---|
| | 258 | function value = checkfield(field,value,optimtbx)
|
| | 259 | %CHECKFIELD Check validity of structure field contents.
|
| | 260 | % CHECKFIELD('field',V,OPTIMTBX) checks the contents of the specified
|
| | 261 | % value V to be valid for the field 'field'. OPTIMTBX indicates if
|
| | 262 | % the Optimization Toolbox is on the path.
|
| | 263 | %
|
| | 264 |
|
| | 265 | % empty matrix is always valid
|
| 78 | 266 | if isempty(value)
|
| | 267 | return
|
| | 268 | end
|
| | 269 |
|
| | 270 | % See if it is one of the valid MATLAB fields. It may be both an Optim
|
| | 271 | % and MATLAB field, e.g. MaxFunEvals, in which case the MATLAB valid
|
| | 272 | % test may fail and the Optim one may pass.
|
| 78 | 273 | validfield = true;
|
| 78 | 274 | switch field
|
| 78 | 275 | case {'TolFun'} % real scalar
|
| | 276 | [validvalue, errmsg, errid] = nonNegReal(field,value);
|
| 78 | 277 | case {'TolX'} % real scalar
|
| | 278 | % this string is for LSQNONNEG
|
| | 279 | [validvalue, errmsg, errid] = nonNegReal(field,value,'10*eps*norm(c,1)*length(c)');
|
| 78 | 280 | case {'Display'} % several character strings
|
| 26 | 281 | [validvalue, errmsg, errid] = displayType(field,value);
|
| 52 | 282 | case {'MaxFunEvals','MaxIter'} % integer including inf or default string
|
| | 283 | % this string is for FMINSEARCH
|
| 26 | 284 | [validvalue, errmsg, errid] = nonNegInteger(field,value,'200*numberofvariables');
|
| 26 | 285 | case {'FunValCheck'} % off,on
|
| 26 | 286 | [validvalue, errmsg, errid] = onOffType(field,value);
|
| | 287 | case {'OutputFcn','PlotFcns'}% function
|
| | 288 | [validvalue, errmsg, errid] = functionOrCellArray(field,value);
|
| | 289 | otherwise
|
| | 290 | validfield = false;
|
| | 291 | validvalue = false;
|
| | 292 | errid = 'MATLAB:optimset:InvalidParamName';
|
| | 293 | errmsg = getString(message(errid, field));
|
| | 294 | end
|
| | 295 |
|
| 78 | 296 | if validvalue
|
| 78 | 297 | return;
|
| | 298 | elseif ~optimtbx && validfield
|
| | 299 | % Throw the MATLAB invalid value error
|
| | 300 | ME = MException(errid,'%s',errmsg);
|
| | 301 | throwAsCaller(ME);
|
| | 302 | else % Check if valid for Optim Tbx
|
| | 303 | [value, optvalidvalue, opterrmsg, opterrid, optvalidfield] = optimoptioncheckfield(field,value);
|
| | 304 | if optvalidvalue
|
| | 305 | return;
|
| | 306 | elseif optvalidfield
|
| | 307 | % Throw the Optim invalid value error
|
| | 308 | ME = MException(opterrid,'%s',opterrmsg);
|
| | 309 | throwAsCaller(ME);
|
| | 310 | else % Neither field nor value is valid for Optim
|
| | 311 | % Throw the MATLAB invalid value error (can't be invalid field for
|
| | 312 | % MATLAB & Optim or would have errored already in optimset).
|
| | 313 | ME = MException(errid,'%s',errmsg);
|
| | 314 | throwAsCaller(ME);
|
| | 315 | end
|
| | 316 | end
|
Other subfunctions in this file are not included in this listing.