isfield

Determine if input is structure array field

Syntax

TF = isfield(S,field)

Description

example

TF = isfield(S,field) returns 1 if field is the name of a field of the structure array S. Otherwise, it returns 0.

If field is an array that contains multiple names, then TF is a logical array that has the same size.

Examples

collapse all

Create a structure.

S.x = linspace(0,2*pi);
S.y = sin(S.x);
S.title = 'y = sin(x)'
S = struct with fields:
        x: [1x100 double]
        y: [1x100 double]
    title: 'y = sin(x)'

Determine if 'title' is the name of a field of S.

TF = isfield(S,'title')
TF = logical
   1

You can test multiple names in one call to the isfield function by specifying them in a cell array or string array.

field = {'x','y','z','title','error'};
TF = isfield(S,field)
TF = 1x5 logical array

   1   1   0   1   0

Input Arguments

collapse all

Structure array.

Potential field names, specified as a character vector, cell array of character vectors, or string array.

Extended Capabilities

Introduced before R2006a