Search code examples
built-inoverridingfunction-handlematlab

How to get a handle to an overriden built-in function?


On my Matlab path there's a custom zeros function. I want to store a handle to the built-in zeros in a variable. How can I do that?

Thought about @(varargin)builtin('zeros',varargin{:}), but this would probably slow down the operation due to the string comparison.

Also, I've noticed that it's possible to refer to diag as @numel\diag, but this doesn't seem to work with other built-in functions (zeros in particular).


Solution

  • Well, this doesn't give you an exact answer to your question, but it could solve the problem:

    I think this seems to be a good solution:

    matlabcentral: How to call a shadowed function

    Withn the last post:

    Just stumbled upon this problem and found the following solution: For example, I have matlab svmtrain shadowed by libsvm toolbox:

    which svmtrain -all

    C:\Projects\Ichilov\Misc\MVPA\libsvm-mat-3.0-1\svmtrain.mexw64

    C:\Program Files\MATLAB\R2009b\toolbox\bioinfo\biolearning\svmtrain.m % Shadowed

    But I can access the original function by using str2func:

    org_svmtrain = str2func([matlabroot '\toolbox\bioinfo\biolearning\svmtrain'])

    and then simply calling:

    org_svmtrain(training, groupnames)