Remove fields from structure
s = rmfield(s,field)
example
s = rmfield(s,field) removes the specified field or fields from structure array s. Specify multiple fields using a cell array of character vectors or a string array. The dimensions of s remain the same.
s
field
collapse all
Define a scalar structure with fields named a, b, and c.
a
b
c
s.a = 1; s.b = 2; s.c = 3;
Remove field b.
field = 'b'; s = rmfield(s,field)
s = struct with fields: a: 1 c: 3
Define a scalar structure with fields first, second, third, and fourth.
first
second
third
fourth
S.first = 1; S.second = 2; S.third = 3; S.fourth = 4;
Remove fields first and fourth.
fields = {'first','fourth'}; S = rmfield(S,fields)
S = struct with fields: second: 2 third: 3
Input structure, specified as a structure array.
Data Types: struct
struct
Field name or names, specified as a character array, cell array of character vectors, or string array.
Example: 'f1'
'f1'
Example: {'f1';'f2'}
{'f1';'f2'}
Data Types: char | cell | string
char
cell
string
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
fieldnames | isfield | orderfields
fieldnames
isfield
orderfields
You have a modified version of this example. Do you want to open this example with your edits?