This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Determine if input is structure array field


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


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.

Extended Capabilities

Introduced before R2006a