Is self-reference possible in MATLAB?

前端 未结 3 1062
臣服心动
臣服心动 2020-12-05 18:15

As noted here, functions in packages, as well as static methods in classes, still need to use a packagename.functionname syntax or import packagename.*

3条回答
  •  生来不讨喜
    2020-12-05 19:00

    This probably is not a bounty worthy answer but as you do not have any answers I thought I would post it anyway! You can invoke static methods via an instance of the class which you would only need to define once. You can invoke functions via a function handle but this would require one handle per function.

    Using these techniques you could define all your static method and function references in one place. Then you would use these references throughout your package. Then if you decided to change the package name at a later point you would only need to update these references which are all stored in one place.

    See:

    Calling Static Methods

    You can also invoke static methods using an instance of the class, like any method:

    obj = MyClass;

    value = obj.pi(.001);

    function_handle (@)

    The following example creates a function handle for the humps function and assigns it to the variable fhandle.

    fhandle = @humps;

提交回复
热议问题