func2str

Converts a function handle to text.

Category: Language Fundamentals > Data Types

Syntax

s = func2str(fh)

Returns the name of a simple handle, or the full text of an anonymous one.

Description

func2str is the inverse of str2func. It is handy for printing which function was used, and for saving an anonymous function as text. The body of an anonymous function is shown in a normalized form, so spacing may differ from how it was typed.

Input arguments

fh
Function handle.

Output arguments

s
Character vector. For @sin it is 'sin' (no @); for an anonymous function it starts with @ and shows the parameter list and body.

Example

Simple and anonymous handles

func2str(@sin)
func2str(@(x, y) x + y)
Output
ans = 'sin'
ans = '@(x,y)x+y'

See also

str2func feval functions cellfun arrayfun