RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • fieldnames
    • getfield
    • isfield
    • orderfields
    • rmfield
    • setfield
    • struct
    • structfun

getfield — Read a field, nested path, or indexed field value.

getfield provides functional field access for scalar structures, structure arrays, and supported RunMat object-family values.

Syntax

value = getfield(S, field)
value = getfield(S, field1, ..., fieldN)
value = getfield(S, idx, field1, ..., fieldN)
value = getfield(S, idx, field1, idx1, ..., fieldN, idxN)

Inputs

S
Type
Any
Required
Yes
Description
Structure or supported RunMat object-family value.
field
Type
PropertyName
Required
Yes
Description
Field name.
path
Type
Any
Required
Variadic
Description
Field names with optional cell-array index selectors.
NameTypeRequiredDefaultDescription
SAnyYes—Structure or supported RunMat object-family value.
fieldPropertyNameYes—Field name.
pathAnyVariadic—Field names with optional cell-array index selectors.

Returns

value
Type
Any
Description
Selected field or property value.
NameTypeDescription
valueAnySelected field or property value.

Errors

RunMat:getfield:TooManyOutputs
When
More than one output is requested.
Message
getfield: too many output arguments
RunMat:getfield:NotEnoughInputs
When
No field path is supplied.
Message
getfield: expected at least one field name
RunMat:getfield:FieldExpected
When
A selector is not followed by a field name.
Message
getfield: expected field name arguments
IdentifierWhenMessage
RunMat:getfield:TooManyOutputsMore than one output is requested.getfield: too many output arguments
RunMat:getfield:NotEnoughInputsNo field path is supplied.getfield: expected at least one field name
RunMat:getfield:FieldExpectedA selector is not followed by a field name.getfield: expected field name arguments
RunMat:getfield:IndexSelectorTypeAn index selector is not a cell array.getfield: indices must be provided in a cell array
RunMat:getfield:InvalidIndexAn index component is invalid.getfield: invalid index element
RunMat:getfield:IndexShapeThe index rank or shape is unsupported for the target.getfield: unsupported index shape for target value
RunMat:getfield:FieldNameTypeA field name is not scalar text.getfield: expected field name
RunMat:getfield:NonStructReferenceField lookup targets an unsupported value.Struct contents reference from a non-struct array object.
RunMat:getfield:IndexOutOfBoundsAn index exceeds the target bounds.Index exceeds the number of array elements.
RunMat:getfield:MissingFieldA requested field is absent.Reference to non-existent field
RunMat:PropertyPrivateAccessA property is inaccessible from the current context.You cannot get this property from the current context.
RunMat:getfield:ObjectPropertyObject property access is invalid.getfield: invalid object property access
RunMat:getfield:InvalidHandleA handle is invalid or deleted.Invalid or deleted handle object
RunMat:getfield:InternalErrorExecution cannot complete the access.getfield: internal error

Field paths

value = getfield(S,field) reads a named field. Additional names traverse nested structures, so getfield(S,'a','b') is the functional form of S.a.b.

Field names are exact and case-sensitive scalar text. A missing member or a path that reaches a non-structure value produces an error.

Structure arrays and indexed fields

Place an index cell before the first field to select one structure-array element: getfield(S,{row,col},'field'). Place one after a field name to apply ordinary parenthesis indexing to that field's contents. Intermediate selections must identify one value; the final selector may return a subarray. Every index is one-based.

Numeric vectors and logical arrays select subarrays under the indexed value's class and shape rules. Parenthesis indexing of a cell field returns a cell array; it does not extract cell contents. RunMat mode additionally accepts textual positive indices and end inside selector cells.

Objects and resident values

RunMat mode extends getfield to supported object, handle, listener, and exception values. Property access observes declared access rules and invokes an available dependent-property getter.

Reading a field directly preserves the stored value, including an accelerator-resident handle. Indexing a resident field is a separately gated RunMat extension that gathers authoritative storage through its owning provider before host indexing.

Examples

Read a scalar structure field

stats = struct('mean', 42, 'stdev', 3.5);
mu = getfield(stats, 'mean')

Expected output:

mu = 42

Traverse nested fields

cfg = struct('solver', struct('name', 'cg', 'tolerance', 1e-6));
tol = getfield(cfg, 'solver', 'tolerance')

Expected output:

tol = 1.0000e-06

Read one structure-array element

records = struct('label', {'first', 'second'}, 'id', {101, 102});
last_id = getfield(records, {2}, 'id')

Expected output:

last_id = 102

Read selected field elements

s = struct('values', {[10 20 30 40]});
selected = getfield(s, 'values', {[2 4]})

Expected output:

selected = [20 40]

Read the first structure-array element by default

records = struct('label', {'first', 'second'}, 'id', {101, 102});
first_label = getfield(records, 'label')

Expected output:

first_label = 'first'

Read a matrix element stored in a field

measurements = struct('values', {[1 2 3; 4 5 6]});
entry = getfield(measurements, 'values', {2, 3})

Expected output:

entry = 6

Use an integer selector without changing the field class

s = struct('values', {uint16([10 20 30])});
selected = getfield(s, 'values', {uint8([3 1])})

Expected output:

selected = uint16([30 10])

Using getfield with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how getfield changes the result.

Run a small getfield example, explain the result, then change one input and compare the output.

FAQ

How do I access a nested field?⌄

List every field in order, as in getfield(S,'parent','child').

How do I select a structure-array element?⌄

Put a cell array of one-based indices before the first field name.

Can I index the value stored in a field?⌄

Yes. Put a numeric or logical selector cell immediately after that field name.

Does direct access gather GPU data?⌄

No. The stored resident handle is returned unchanged. Indexing that value requires the RunMat indexed-resident extension and a provider-owned gather.

Do dependent properties run getter methods?⌄

In RunMat mode, supported dependent properties invoke their getter when one is available; object-family access is an explicit extension.

What happens for an invalid handle?⌄

The RunMat object-family extension reports an invalid-handle error before attempting property access.

Related Structs functions

fieldnames · isfield · orderfields · rmfield · setfield · struct · structfun

Source you can read

Every RunMat function's source is public. Read exactly how getfield is executed, line by line, in Rust.

  • View the source for getfield 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Field paths
  • Structure arrays and indexed fields
  • Objects and resident values
  • Examples
  • Read a scalar structure field
  • Traverse nested fields
  • Read one structure-array element
  • Read selected field elements
  • Read the first structure-array element by default
  • Read a matrix element stored in a field
  • Use an integer selector without changing the field class
  • Using getfield with coding agents
  • FAQ
  • Related Structs functions
  • Source you can read
  • About RunMat