Execute built-in function from overloaded method
builtin(function,x1,...,xn) executes the built-in function with the input arguments x1 through xn. Use builtin to execute the original built-in from within a method that overloads the function. To work properly, you must never overload builtin.
Execute the built-in functionality from within an overloaded method.
Create a simple class describing the speed of a particle and providing a disp method by pasting the following code into a file called MyParticle.m.
classdef MyParticle properties velocity; end methods function p = MyParticle(x,y,z) p.velocity.x = x; p.velocity.y = y; p.velocity.z = z; end function disp(p) builtin('disp',p) %call builtin if isscalar(p) disp(' Velocity') disp([' x: ',num2str(p.velocity.x)]) disp([' y: ',num2str(p.velocity.y)]) disp([' z: ',num2str(p.velocity.z)]) end end end end
Create an instance MyParticle.
p = MyParticle(1,2,4)
p = MyParticle Properties: velocity: [1x1 struct] Methods Velocity x: 1 y: 2 z: 4
A built-in function is part of the MATLAB executable. MATLAB does not implement these functions in the MATLAB language. Although most built-in functions have a .m file associated with them, this file only supplies documentation for the function.
You can use the syntax which function to check whether a function is built-in.