Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

isfield - Determine whether input is structure array field

Syntax

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

Description

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).

Examples

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.

isfield(patient,'billing')
ans =
     1

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

fieldnames, setfield, getfield, orderfields, rmfield, struct, isstruct, iscell, isa, is*, dynamic field names

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS