Documentation Center

  • Trial Software
  • Product Updates


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 the quoted string '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.

tf = isfield(S, C) examines structure S for multiple fieldnames as specified in cell array of strings 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).

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


Example 1 — Single Fieldname Syntax

Given the following MATLAB® structure,

patient.name = '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

See Also

| | | | | | | | |

Was this topic helpful?