Main Content

at symbol, @

Create anonymous functions and function handles, call superclass methods

Syntax

Description

The at symbol (@) creates handles to anonymous and named functions, and is also used to call superclass methods from within a subclass. For instance, f = @(x,y) x+y creates an anonymous function that accepts two inputs and adds them together.

example

Examples

expand all

Create a function handle to an anonymous function.

fh = @(x,y) x.^2 + y.^2
fh = function_handle with value:
    @(x,y)x.^2+y.^2

Call the function with two inputs to supply values for x and y.

fh(2,3)
ans = 
13

Create a function handle to a named function.

fhandle = @max
fhandle = function_handle with value:
    @max

Call the function with a vector input.

fhandle([1 4 10])
ans = 
10

Call the disp method of MySuperclass from within a subclass.

disp@MySuperclass(obj)

Call the superclass constructor from a subclass using the object being constructed.

obj = obj@MySuperclass(arg1,arg2,..)

Version History

Introduced before R2006a