feval — Invoke a function selected by name, handle, closure, or supported receiver.
feval dynamically resolves a callable and forwards arguments and requested outputs without imposing its own numeric or provider semantics.
Syntax
[varargout] = feval(f, varargin)Inputs
f- Type
Any- Required
- Yes
- Description
- Function handle, handle text, closure, or object receiver.
varargin- Type
Any- Required
- Variadic
- Description
- Function call arguments.
Returns
varargout- Type
Any- Description
- Function return value(s).
Returned values from feval depend on how many outputs the caller requests.
Errors
RunMat:FevalHandleNameInvalid- When
- A function or method handle name is empty.
- Message
feval: function handle name must not be empty
RunMat:FevalHandleShapeInvalid- When
- Text handle input has invalid char/string array shape.
- Message
feval: function handle text input must be scalar row text
RunMat:SemanticFunctionUnavailable- When
- Semantic function identity cannot be invoked in current runtime state.
- Message
feval: semantic function handle is unavailable
RunMat:FevalFunctionValueUnsupported- When
- The first argument is not a supported callable value.
- Message
feval: unsupported function value
Behavior
feval(fun, x1, ..., xN) invokes a callable selected at runtime. Plain character-vector or string-scalar names use the same resolution path as direct named calls. Function handles use their bound identity, and closures retain captured values.
Arguments are forwarded without numeric conversion. Output count, class, shape, errors, overflow behavior, side effects, and residency belong to the selected callable and the number of outputs requested at the call site.
RunMat mode additionally accepts text targets prefixed with @ and supported callable object receivers. A MATLAB compatibility pin rejects those extensions before dispatch; ordinary names and actual function handles remain compatible.
GPU execution
feval performs no provider operation of its own. The selected callable determines whether resident inputs remain on their owner, launch a kernel, use a typed fallback, gather, or are rejected.
Examples
Call a function by its plain name
y = feval("round", pi, 2)Expected output:
y = 3.14Call a bound function handle
f = @max;
y = feval(f, int32([2 7 4]))Expected output:
y = int32(7)Forward the requested output count
[value, index] = feval(@max, uint64([4 9 2]))Expected output:
value = uint64(9); index = 2Invoke a closure with captured values
offset = 3;
f = @(x) x.^2 + offset;
y = feval(f, [1 2 3])Expected output:
y = [4 7 12]Dispatch to a provider-capable function
G = gpuArray([0 pi/2 pi]);
H = feval(@sin, G);
host = gather(H)Expected output:
host = [0 1 0] within floating toleranceUse an @-prefixed text target in RunMat mode
y = feval("@sin", pi / 2)Expected output:
y = 1Using feval with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how feval changes the result.
Run a small feval example, explain the result, then change one input and compare the output.
FAQ
Does feval convert integer arguments to double?⌄
No. It forwards each value unchanged; conversion and output-class rules belong to the selected callable.
Does feval gather a gpuArray?⌄
Not by itself. The selected callable's provider contract controls residency and fallback.
Can I pass a plain function name?⌄
Yes. Character-vector and scalar-string names are compatible callable selectors.
Is an actual function handle compatible?⌄
Yes. Values such as @sin invoke their bound callable identity.
Is an @-prefixed string portable?⌄
No. Text such as "@sin" is a RunMat extension; use "sin" or @sin for compatible source.
Why can output facts be dynamic?⌄
The target and requested output count can be known only at runtime. When the target is statically known, the compiler can reuse its catalog contract.
Related Introspection functions
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · findprop · func2str · 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 feval is executed, line by line, in Rust.
- View the source for feval 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.