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

function, function-calls, matlab, oop, operator-precedence

Solution

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:

- Change the function's name.

- Move the function's body to the same script that is calling the function (item 4 on the list above)

- 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.

Problem

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?

Original source

Related problems