inline

Creates a function object from a text expression (older style).

Category: Language Fundamentals > Matrices and Arrays

Syntax

f = inline(expr)

Builds a function of the variables found in expr.

f = inline(expr, arg1, arg2, ...)

Fixes the argument names and their order.

Description

Without explicit names, the arguments are the identifiers in the expression, in alphabetical order. This is why inline('a*x+b') takes (a, b, x); give the names to control the order.

Anonymous functions, @(x) x.^2 + 1, replace inline in current code: they are faster and capture variables from the workspace.

Input arguments

expr
Text with a MATLAB expression, such as 'x^2 + 1'.
arg1, ...
Names of the arguments.

Output arguments

f
An inline function object. Call it like a function; formula(f) and argnames(f) read it back.

Example

f = inline('a*x + b', 'x', 'a', 'b');
f(2, 3, 4)
formula(f)
Output
ans = 10
ans = 'a*x + b'

See also

formula argnames feval func2str