Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force matlab to call a regular function rather than class method when they are overloaded?

Assume I have an object X of class MyClass. MyClass has a method compute, and when I call U = compute(X,...), matlab automatically calls the class method. However, what I actually want is to call another function also called compute whose parameters start with a MyClass object though. How do I force matlab to call this regular function rather than go into the class method?

like image 935
OneZero Avatar asked Jul 10 '13 16:07

OneZero


1 Answers

There is no way to do this without making some changes either to the function's name or location. If you check Matlab's function precedence order, methods always run before normal external functions. Your only practical options are:

  1. Change the function's name.
  2. Move the function's body to the same script that is calling the function (item 4 on the list above)
  3. Move the function's .m file to a folder called private in the same folder as your script file (item 5 on the list)

UPDATE

Although not quite practical for smaller projects, you may also want to look into packaging your functions. A good discussion can be found in this SO post.

like image 173
Bee Avatar answered Oct 21 '22 11:10

Bee