Programmatically testing whether a variable is an optimoptions object
1 view (last 30 days)
I was wondering if there was something like an isoptimoptions function that could be used to test in general whether a variable was generated by optimoptions(). The isa command alone will not seem to do it, because optimoptions objects occupy separate classes, depending on which solver the object was generated for.
>> whos opts1 opts2
Name Size Bytes Class Attributes
opts1 1x1 29913 optim.options.Lsqnonlin
opts2 1x1 14775 optim.options.Linprog
The following user-defined command seems to work, but I'm wondering if there are more direct alternatives,
bool = startsWith(class(opts),'optim.options')
Guillaume on 28 Feb 2020
Edited: Guillaume on 28 Feb 2020
"those I've checked all seem to have 'optim.options.SolverOptions' as a parent in common."
In that case:
Strangely enough the base class optim.options.SolverOptions is part of base matlab (or a toolbox I've got even though I've haven't got the optimisation toolbox) and available as an m file.
The comment in the m file does say that this is the "base class for Optimization Toolbox options", so yes, the above is what you want.