mfilename — Return the lexical file name or current method class.
mfilename inspects the currently executing source context without opening a file. RunMat returns a host string scalar; in a context without a lexical file or class, the result is empty.
Syntax
name = mfilename()
name = mfilename(option)Inputs
option- Type
Any- Required
- Yes
- Default
- —
- Description
- 'fullpath' or 'class'; other values preserve the default name mode.
Returns
name- Type
StringScalar- Description
- Host string scalar naming the lexical source or method class.
Errors
RunMat:TooManyInputs- When
- More than one option argument is provided.
- Message
mfilename: too many input arguments
Forms and source ownership
mfilename returns the lexical file stem without its extension. mfilename('fullpath') returns the lexical full path without extension. Nested eval source retains its owning lexical file. A source without a file returns an empty string.
mfilename('class') reads the current method's class-access context and returns its class name, or an empty string outside such a context. Option spelling is trimmed and case-insensitive. Unsupported or non-text options preserve the default name mode; more than one option raises RunMat:TooManyInputs.
The result is a RunMat string scalar. It is source-context metadata, not a filesystem existence test or path-resolution operation. No operand payload is gathered and no GPU kernel is launched.
Example
Inspect an unbound source context
name = mfilename(); full = mfilename('fullpath');Using mfilename with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how mfilename changes the result.
Run a small mfilename example, explain the result, then change one input and compare the output.
FAQ
Does fullpath read the file?⌄
No. The result is derived from the lexical source record already attached to execution.
Related Introspection functions
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · 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 · 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 mfilename is executed, line by line, in Rust.
- View the source for mfilename 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.