Main Content

rmfield

Remove fields from structure

Description

example

s = rmfield(s,field)removes the specified field or fields from structure arrays. Specify multiple fields using a cell array of character vectors or a string array. The dimensions ofsremain the same.

Examples

collapse all

Define a scalar structure with fields nameda,b, andc.

s.a = 1; s.b = 2; s.c = 3;

Remove fieldb.

field ='b'; s = rmfield(s,field)
s =struct with fields:a: 1 c: 3

Define a scalar structure with fieldsfirst,second,third, andfourth.

S.first = 1; S.second = 2; S.third = 3; S.fourth = 4;

Remove fieldsfirstandfourth.

fields = {'first','fourth'}; S = rmfield(S,fields)
S =struct with fields:second: 2 third: 3

Input Arguments

collapse all

Input structure, specified as a structure array.

Data Types:struct

Field name or names, specified as a character array, cell array of character vectors, or string array.

Example:'f1'

Example:{'f1';'f2'}

Data Types:char|cell|string

Extended Capabilities

Introduced before R2006a