Programmatically testing whether a variable is an optimoptions object
Afficher commentaires plus anciens
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.
>> opts1=optimoptions('lsqnonlin');
>> opts2=optimoptions('linprog');
>> 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,
function bool=isaoptimoptions(opts)
bool = startsWith(class(opts),'optim.options')
end
4 commentaires
Guillaume
le 27 Fév 2020
I don't have the toolbox so can't test, but don't they all derive from the same (possibly abstract) base class?
Matt J
le 27 Fév 2020
Guillaume
le 28 Fév 2020
superclasses(obj)
will tell you the base classes (if any). isa on the base class would work.
Matt J
le 28 Fév 2020
Réponse acceptée
Plus de réponses (1)
Catégories
En savoir plus sur Surrogate Optimization dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!