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 whether input is structure array field


tf = isfield(S,fieldname)
tf = isfield(S,C)


tf = isfield(S,fieldname) examines structure S to see if it includes the field specified by fieldname. Output tf is set to logical 1 (true) if S contains the field, or logical 0 (false) if not. If S is not a structure array, isfield returns false. The input argument fieldname can be a character vector or a string scalar.

tf = isfield(S,C) examines structure S for multiple fieldnames as specified in C, and returns an array of logical values to indicate which of these fields are part of the structure. Elements of output array tf are set to a logical 1 (true) if the corresponding element of C holds a fieldname that belongs to structure S. Otherwise, logical 0 (false) is returned in that element. In other words, if structure S contains the field specified in C(m,n), isfield returns a logical 1 (true) in tf(m,n). The input argument C can be a cell array of character vectors or a string array.


isfield returns false if the field or fieldnames input is empty.


Example 1 — Single Fieldname Syntax

Given the following MATLAB® structure, = 'John Doe';
patient.billing = 127.00;
patient.test = [79 75 73; 180 178 177.5; 220 210 205];

isfield identifies billing as a field of that structure.

ans =

Example 2 — Multiple Fieldname Syntax

Check structure S for any of four possible fieldnames. Only the first is found, so the first element of the return value is set to true:

S = struct('one', 1, 'two', 2);

fields = isfield(S, {'two', 'pi', 'One', 3.14})
fields =
     1     0     0     0

Extended Capabilities

Introduced before R2006a