fieldnames — List structure fields and supported RunMat object properties.
fieldnames returns a column cell array of character-row names without reading or gathering stored values.
Syntax
names = fieldnames(S)Inputs
S- Type
Any- Required
- Yes
- Description
- Structure or supported RunMat object.
Returns
names- Type
Any- Description
- Column cell array of character-row names.
Errors
RunMat:fieldnames:TooManyOutputs- When
- More than one output is requested.
- Message
fieldnames: too many output arguments
RunMat:fieldnames:InvalidTarget- When
- Input is not a structure or supported RunMat object.
- Message
fieldnames: expected struct, struct array, or supported object
RunMat:fieldnames:InternalError- When
- Output construction or internal metadata processing fails.
- Message
fieldnames: internal error
Structure field order
fieldnames(S) returns an N-by-1 cell array of character rows. A scalar structure retains insertion order and comparisons remain case-sensitive.
Structure arrays retain one ordered field schema across every element. Empty scalar structures return a 0-by-1 cell array; empty structure arrays retain and report their declared field schema.
Object-family extension
In RunMat compatibility mode, value objects, handle objects, and listeners expose the property metadata currently represented by the runtime. Class-declared nonstatic properties, inherited properties, dynamic instance properties, and valid handle-target metadata are merged into a deterministic result.
Object-family introspection is a RunMat extension rather than a claim of complete MATLAB object-property policy. MATLAB compatibility mode rejects these object inputs before inspecting them.
Residency and execution
fieldnames reads host-side metadata only. Values nested in a structure or object are not evaluated or gathered, so resident tensor handles remain owned by their provider. The operation launches no accelerator kernel and is a fusion boundary.
Examples
List scalar structure fields
s = struct('name', 'entry', 'score', 42);
fields = fieldnames(s)Expected output:
fields = {'name'; 'score'}Check fields before access
stats = struct('min', 1.2, 'max', 9.8);
fields = fieldnames(stats);
hasMedian = any(strcmp(fields, 'median'))Expected output:
hasMedian = falseList structure-array fields
entries = struct('name', {'first', 'second'}, 'id', {101, 102});
fields = fieldnames(entries)Expected output:
fields = {'name'; 'id'}List fields in a nested structure
config.database = struct('host', 'db.local', 'port', 5432);
names = fieldnames(config.database)Expected output:
names = {'host'; 'port'}Handle empty structures
emptyScalar = struct();
emptyArray = struct('id', {});
fs = fieldnames(emptyScalar);
fa = fieldnames(emptyArray)Expected output:
fs is 0-by-1; fa contains the declared field 'id'Keep case-distinct names
s = struct('name', 1, 'Name', 2);
names = fieldnames(s)Expected output:
names = {'name'; 'Name'}Using fieldnames with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how fieldnames changes the result.
Run a small fieldnames example, explain the result, then change one input and compare the output.
FAQ
What does fieldnames return?⌄
An N-by-1 cell array whose elements are character-row field names.
Are field names sorted?⌄
Scalar structures and structure arrays retain field insertion order. Supported object families use deterministic property ordering.
Can fieldnames inspect structure arrays?⌄
Yes. It returns the array's ordered field schema, including the retained schema of an empty structure array. Ordinary cell arrays remain cells even when their elements are structures.
Can fieldnames inspect objects?⌄
RunMat compatibility mode supports the currently represented value, handle, and listener properties as an explicit extension. MATLAB compatibility mode rejects that extension.
Does fieldnames gather GPU data?⌄
No. It inspects metadata and leaves nested provider-resident values untouched.
Are unsupported inputs converted?⌄
No. Numeric, logical, text, and resident array inputs reject without conversion.
Related Structs functions
Source you can read
Every RunMat function's source is public. Read exactly how fieldnames is executed, line by line, in Rust.
- View the source for fieldnames 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.