str2func

Returns the function handle corresponding to the input string argument s. If an optional second argument called global is given, only global functions are included in the scope of the lookup.

Syntax

R = str2func(s)

R = str2func(s, 'global')

Inputs

s
Function name.
Type: string

Outputs

R
Type: Function handle.

Examples

Local function example:
function testfunc()
disp('test')
end
str2func('testfunc')
R = testfunc
Global function example:
 R = str2func('sqrt')
R = sqrt