function-handle

Programming

Create a handle (reference) to a named function. The @ symbol followed by a function name (no parentheses) creates a callable reference. Pass function handles to functions like ode45, fminsearch, etc.

Syntax

fh = @functionName
@sin
@cos
@mean

Examples

fh = @sin;
fh(pi/2)
▶ Run
sol = ode45(@(t,y) -y, [0, 5], [1])
▶ Run
result = fminsearch(@(x) (x-3)^2, 0)
▶ Run

See Also

Try SimLab — Free MATLAB® Alternative

466 functions. Runs in your browser. No install.

Open SimLab

Stay Updated

Get notified about new simulations and tools. We send 1-2 emails per month.