rmfield

Removes fields from a structure.

Category: Language Fundamentals > Data Types

Syntax

s2 = rmfield(s, field)

Removes the field named field.

s2 = rmfield(s, fields)

Removes several fields given as a cell array or string array.

Description

The field must exist; otherwise rmfield raises an error, so check with isfield when unsure. For a structure array the field is removed from every element. The original variable is not changed, so assign the result.

Input arguments

s
Structure or structure array.
field(s)
Name(s) of fields that exist in s.

Output arguments

s2
Structure without those fields.

Example

s = struct('a', 1, 'b', 2, 'c', 3);
s = rmfield(s, {'a','c'})
isfield(s, 'a')
Output
s = struct with fields:

    b: 2
ans = logical
   0

See also

setfield getfield isfield fieldnames struct orderfields