A few pieces of documentation explain the behavior where the import list for the function does not update. From the IMPORT doc:
The import list of a function is persistent across calls to that function and is only cleared when the function is cleared.
You can not clear the import list from a function workspace. To clear the base workspace only, use: clear import
As a result, only clearing the function clears its import list.
I would suggest you pursue object-oriented programming in order to get the polymorphism it appears you want. For example, create the following two classes:
- MyClass1.m:
classdef MyClass1 < handle
methods
function commonFunction(obj)
disp('Using MyClass1')
end
end
end
- MyClass2.m:
classdef MyClass2 < handle
methods
function commonFunction(obj)
disp('Using Myclass2')
end
end
end
Now you can essentially use an object to dispatch to the appropriate implementation of commonFunction:
>> id1 = MyClass1;
>> id2 = MyClass2;
>> commonFunction(id1)
Using MyClass1
>> commonFunction(id2)
Using Myclass2