Main Content


Determine if input is structure array field



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 and S is a structure array, then TF is a logical array that has the same size.

If S is not a structure array, then isfield returns 0.


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

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.


  • If the input argument S is an object, then isfield always returns 0, even when field is the name of a property.

    To determine if a name is the name of a property of an object, use the isprop function.

Extended Capabilities

Introduced before R2006a