MATLAB: Enforcing that a class method is called instead of an “imported” function with the same name

object oriented programming in matlab

Hi all,
I have a function called process(arg0, obj) that accepts two arguments. The second can be either a numeric matrix or an object of a custom made class (say, of class MyClass). The latter class has a method called dosomething. Within process(), I have the following code:
import MISC.dosomething;
dosomething(obj);
Where MISC is just a package where I have placed a function called dosomething (this is a normal function, not a method of any object). Obviously, what I want is that, if obj is of class MyClass, the class-associated method dosomething is called while, if obj is anything else but a MyClass object, the function MISC.dosomething is called. However, no matter what, function MISC.something is always called, even if obj is of class MyClass. I find this behavior rather counter-intuitive as I would expect that objects methods have higher preference than imported functions. Is there any way to enforce that MATLAB chooses object methods rather than an imported function that has the same name?
Thanks in advance.
Best,
Germán

Best Answer

I haven't read the documentation on "Scoping Classes with Packages"
but it seems relevant. More to the point, this piece of documentation says don't do what you are trying to do