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

struct — Create scalar structs or struct arrays from field/value inputs.

struct creates scalar structs and struct arrays from name/value pairs, copies existing structs, and expands equally shaped cell-valued fields.

Syntax

S = struct()
S = struct(template)
S = struct(field, value, ...)

Inputs

template
Type
Any
Required
Yes
Description
Existing struct/array template or empty array.
field
Type
PropertyName
Required
Yes
Description
Field name.
value
Type
Any
Required
Yes
Description
Field value or cell array.
name_value_pairs
Type
Any
Required
Variadic
Description
Additional field/value pairs.
NameTypeRequiredDefaultDescription
templateAnyYes—Existing struct/array template or empty array.
fieldPropertyNameYes—Field name.
valueAnyYes—Field value or cell array.
name_value_pairsAnyVariadic—Additional field/value pairs.

Returns

S
Type
Any
Description
Scalar struct or struct array.
NameTypeDescription
SAnyScalar struct or struct array.

Errors

RunMat:struct:TooManyOutputs
When
More than one output is requested.
Message
struct: too many output arguments
RunMat:struct:InvalidSingleInput
When
Single input is not a valid struct template.
Message
struct: expected name/value pairs, an existing struct or struct array, or [] to create an empty struct array
RunMat:struct:NameValuePairs
When
Arguments are not complete pairs.
Message
struct: expected name/value pairs
IdentifierWhenMessage
RunMat:struct:TooManyOutputsMore than one output is requested.struct: too many output arguments
RunMat:struct:InvalidSingleInputSingle input is not a valid struct template.struct: expected name/value pairs, an existing struct or struct array, or [] to create an empty struct array
RunMat:struct:NameValuePairsArguments are not complete pairs.struct: expected name/value pairs
RunMat:struct:DuplicateFieldA field name appears more than once.struct: field names must be unique
RunMat:struct:CellSizeMismatchCell values have mismatched shapes.struct: cell inputs must have matching sizes
RunMat:struct:SizeOverflowRequested size exceeds limits.struct: struct array size exceeds platform limits
RunMat:struct:AssembleFailedInternal assembly failed.struct: failed to assemble struct array
RunMat:struct:EmptyArrayFailedEmpty array creation failed.struct: failed to create empty struct array
RunMat:struct:StructArrayContentsCell contains non-struct values.struct: single argument cell input must contain structs
RunMat:struct:StructArrayCopyFailedStruct array copy failed.struct: failed to copy struct array
RunMat:struct:FieldNameTypeField name has invalid type.struct: field names must be strings or character vectors
RunMat:struct:FieldNameScalarField name is not scalar.struct: field names must be scalar string arrays or character vectors
RunMat:struct:FieldNameCharVectorCharacter field name is not a row vector.struct: field names must be 1-by-N character vectors
RunMat:struct:FieldNameEmptyField name is empty.struct: field names must be nonempty
RunMat:struct:FieldNameStartCharField name is not a valid identifier.struct: field names must be valid MATLAB identifiers

Behavior

struct() creates a scalar struct with no fields. Name/value pairs create fields in insertion order; duplicate field names raise an error. Field names must be nonempty MATLAB identifiers within namelengthmax and cannot be language keywords.

When any value is a cell array, every cell-valued field must have the same shape. Each cell contributes to the corresponding struct-array element, while non-cell values are replicated across the array. struct([]) creates a 0-by-0 struct array.

struct(S) copies an existing scalar struct or struct array. Numeric fields retain exact class, shape, and storage. Construction does not gather resident values or otherwise transform field payloads.

GPU execution

Struct assembly is host bookkeeping, not a provider operation. A gpuArray field remains an owned resident handle inside the result; no kernel or implicit download occurs.

Examples

Create a scalar struct with named fields

s = struct("name", "entry", "score", 42)

Expected output:

s has fields name and score

Build a struct array from cell-valued fields

names = {"first", "second"};
ages = {36, 45};
records = struct("name", names, "age", ages)

Expected output:

records is a 1-by-2 struct array

Replicate a scalar field across a struct array

ids = struct("id", {101, 102, 103}, "department", "Research")

Expected output:

ids is a 1-by-3 struct array

Copy an existing struct

a = struct("id", 7, "label", "demo");
b = struct(a);
b.id = 8

Expected output:

a.id is 7 and b.id is 8

Create an empty struct array

s = struct([]);
shape = size(s)

Expected output:

shape = [0 0]

Keep a gpuArray field resident

G = gpuArray(uint16([1 2; 3 4]));
s = struct("data", G, "label", "resident");
host = gather(s.data)

Expected output:

host remains a uint16 matrix

Using struct with coding agents

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

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

FAQ

Which field names are valid?⌄

Names must satisfy MATLAB identifier rules: start with a letter, contain only letters, digits, or underscores, fit within namelengthmax, and not be a keyword.

How do I create a struct array?⌄

Use equally shaped cell arrays as field values. Non-cell field values are replicated across every result element.

What happens when a field name repeats?⌄

Duplicate field names are rejected with RunMat:struct:DuplicateField.

What does struct([]) return?⌄

It returns a 0-by-0 struct array.

Does struct copy an existing struct?⌄

Yes. struct(S) returns an independent copy of a supported struct or struct array.

Does construction gather GPU fields?⌄

No. Resident handles remain resident field values until another operation explicitly uses or gathers them.

Related Structs functions

fieldnames · getfield · isfield · orderfields · rmfield · setfield · structfun

Source you can read

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

  • View the source for struct 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
  • Behavior
  • GPU execution
  • Examples
  • Create a scalar struct with named fields
  • Build a struct array from cell-valued fields
  • Replicate a scalar field across a struct array
  • Copy an existing struct
  • Create an empty struct array
  • Keep a gpuArray field resident
  • Using struct with coding agents
  • FAQ
  • Related Structs functions
  • Source you can read
  • About RunMat