Calling an object method where the name of the method is a varible

2 vues (au cours des 30 derniers jours)
Eric
Eric le 25 Jan 2019
Commenté : Eric le 25 Jan 2019
I am trying to call an object method when I have the object instance, the method name, and the argument value(s) as variables. If my object were a COM object, I could use invoke(). Is there something similar to this for user-defined classes? I'm trying to avoid using eval().

Réponse acceptée

Matt J
Matt J le 25 Jan 2019
You can just do,
object.(methodname)(arg1,arg2,...)
  1 commentaire
Eric
Eric le 25 Jan 2019
Thanks! I didn't realize the dynamic field name syntax for structures also works for objects.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by