rmfield — Remove one or more top-level fields from a structure or structure array.
rmfield returns a structure with exact, case-sensitive field names removed while preserving structure-array shape and retained values.
Syntax
S2 = rmfield(S, fields)
S2 = rmfield(S, fields, ...)Inputs
S- Type
Any- Required
- Yes
- Description
- Input structure or structure array.
fields- Type
Any- Required
- Yes
- Description
- Character row, string value, string array, or cell collection of field names.
fields- Type
Any- Required
- Yes
- Description
- First field-name value or collection.
more_fields- Type
Any- Required
- Variadic
- Description
- Additional RunMat-only field-name arguments.
Returns
S2- Type
Any- Description
- Structure or structure array with the selected fields removed.
Errors
RunMat:rmfield:TooManyOutputs- When
- More than one output is requested.
- Message
rmfield: too many output arguments
RunMat:rmfield:NotEnoughInputs- When
- No field-name argument is supplied.
- Message
rmfield: not enough input arguments
RunMat:rmfield:InvalidTarget- When
- The first input is not a structure.
- Message
rmfield: expected struct or struct array
Field removal
S2 = rmfield(S,fields) returns a structure with every requested top-level field removed. S may be a scalar structure or structure array. fields may be a character row, string value, string array, or cell array of character rows and scalar strings.
Every distinct requested name must exist on every structure element. Names are exact and case-sensitive. Duplicate names are removed once; an empty collection removes nothing, while an empty individual name is invalid.
Compatibility and structure arrays
MATLAB compatibility mode accepts one field-name argument. RunMat mode also accepts separate variadic field-name arguments and flattens them in call order. Use one string array or cell array when the source must remain within the MATLAB form.
Removing fields preserves structure-array dimensions and updates the shared ordered schema. Ordinary cell arrays are not structure arrays, regardless of their contents.
Value and residency preservation
The input value is not mutated. RunMat consumes or copies the outer value according to ordinary value semantics and removes only field-map entries. Retained values preserve their class, payload, and provider ownership.
rmfield launches no accelerator kernel and does not gather nested resident values. It runs as a host metadata operation and forms a fusion boundary.
Examples
Remove one field
s = struct('name', 'entry', 'score', 42);
t = rmfield(s, 'score')Expected output:
t contains only the name fieldRemove fields listed in a cell array
cfg = struct('mode', 'fast', 'rate', 60, 'debug', true);
trimmed = rmfield(cfg, {'rate', 'debug'})Expected output:
trimmed contains only the mode fieldRemove fields listed in a string array
stats = struct('mean', 10, 'median', 9, 'stdev', 2);
reduced = rmfield(stats, ["mean", "median"])Expected output:
reduced contains only the stdev fieldRemove a field from every structure
entries = struct('name', {'first', 'second'}, 'id', {101, 102});
trimmed = rmfield(entries, 'id')Expected output:
every element retains only nameRemove an optional field
record = struct('id', 7, 'notes', 'draft');
if isfield(record, 'notes')
record = rmfield(record, 'notes');
endExpected output:
record contains only idUse separate field arguments in RunMat mode
s = struct('a', 1, 'b', 2, 'c', 3);
t = rmfield(s, 'a', "b")Expected output:
t contains only cUsing rmfield with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how rmfield changes the result.
Run a small rmfield example, explain the result, then change one input and compare the output.
FAQ
Does rmfield modify its input in place?⌄
No. It returns a value with the selected fields removed; the caller's original value retains ordinary value semantics.
Which field-name inputs are accepted?⌄
One character row, string value, string array, or cell array of character rows and scalar strings. RunMat mode additionally accepts multiple separate field-name arguments.
What happens when a field is missing?⌄
The call fails with a missing-field error. For a structure array, every requested name must exist on every element.
Are duplicate or empty names accepted?⌄
Duplicate names are removed once. Empty individual names are invalid; an empty string or cell collection requests no removals.
Can rmfield remove nested fields?⌄
No. It removes top-level fields only.
Does rmfield gather GPU data?⌄
No. Retained resident field values remain with their owning provider because only outer metadata changes.
Related Structs functions
fieldnames · getfield · isfield · orderfields · setfield · struct · structfun
Source you can read
Every RunMat function's source is public. Read exactly how rmfield is executed, line by line, in Rust.
- View the source for rmfield 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.