Documentation Center

  • Trial Software
  • Product Updates

builtin

Execute built-in function from overloaded method

Syntax

  • builtin(function,x1,...,xn) example
  • [y1,...,yn] = builtin(function,x1,...,xn)

Description

example

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.

[y1,...,yn] = builtin(function,x1,...,xn) stores any output from function in y1 through yn.

Examples

expand all

Run an Overloaded Function within a Class Definition

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

Input Arguments

expand all

function — Built-in function name string

Valid built-in function name in the MATLAB® path, specified as a string. function cannot be a function handle.

x1,...,xn — Valid input arguments for functionsupported data types

Valid input arguments for function, specified by supported data types.

More About

expand all

built-in function

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.

See Also

|

Was this topic helpful?