func2str — Return the stored function-name text of a function handle.
name = func2str(fh) returns a RunMat string scalar containing the name stored by a named, external, method, bound, or closure function handle. It reads handle metadata without calling the function or resolving an executable target.
Syntax
name = func2str(fh)Inputs
fh- Type
Callable- Required
- Yes
- Default
- —
- Description
- Function handle value.
Returns
name- Type
StringScalar- Description
- Function name string.
Errors
RunMat:Func2StrHandleTypeInvalid- When
- Input is not a supported function handle value.
- Message
func2str: expected function handle
RunMat:func2str:TooManyOutputs- When
- More than one output is requested.
- Message
func2str: too many output arguments
Supported behavior
Exactly one function handle is required. Numeric values, text, cells, objects, and provider-resident numeric values are not converted to handles. Non-handle inputs reject before provider access.
Named, qualified, method, and bound handles return their stored name. A closure returns its stored internal function name; captured values are not included in the text.
The operation does not invoke a callback, load a function, or grant the returned text any execution authority. Converting the text back with str2func does not preserve a bound handle's original source authority or a closure's captured workspace.
Zero or one output is supported. Asking for more than one output rejects before inspecting handle metadata.
MATLAB compatibility limits
MATLAB returns a character vector. RunMat currently returns a string scalar, so callers that need a character vector must convert the result explicitly.
MATLAB represents anonymous functions as expression text. RunMat currently returns a closure's stored internal function name and does not reconstruct an anonymous expression. Text round-tripping is therefore not a way to serialize closures.
Execution and placement
Handle text is host metadata. func2str has no numeric kernel, gather, device output, or numeric precision conversion. Existing text ownership is retained without copying captured workspace values.
Examples
Inspect a named handle
f = @sin;
name = func2str(f);Read a name without resolving or invoking it
f = str2func('func2str_unregistered_example_target');
name = func2str(f);Inspect a closure without executing its body
f = @(x) error('func2str must not invoke this callback');
name = func2str(f);Using func2str with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how func2str changes the result.
Run a small func2str example, explain the result, then change one input and compare the output.
Related Introspection functions
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · findprop · functions · get.p · getcallinfo · getmethod · inputname · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · isvalid · keyboard · loadobj · localfunctions · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mfilename · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · new_object · notify · numArgumentsFromSubscript · onCleanup · parse · saveobj · set.p · stats · str2func · subsasgn · subsref · superclasses · underlyingType · verLessThan · version · which · who · whos
Source you can read
Every RunMat function's source is public. Read exactly how func2str is executed, line by line, in Rust.
- View the source for func2str in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.