fcnchk
Turns a function name or expression into a callable function.
Category: Other public functions: funfun
Syntax
f = fcnchk(fun)
Returns fun unchanged if it is already a function handle, or builds a function from text.
Description
fcnchk was written so that older numerical routines could accept either a handle or a string. A function name such as 'sin' becomes a handle to that function. A string containing an expression is turned into a function of its free variable, x by default, so fcnchk('x^2+1') can be evaluated at any value.
New code should pass handles (@sin, @(x) x.^2 + 1) and skip this check.
Input arguments
fun- A function handle, a function name as text, or an expression in
xas text such as'x^2+1'.
Output arguments
f- Something that can be called with
f(value).
Example
Handle or text
f = fcnchk(@sin);
f(0)
g = fcnchk('x^2+1');
g(2)
Output
ans = 0
ans = 5
Notes
MatLivre returns an inline function for text expressions, as older MATLAB releases do.