Documentation

isfield

Determine whether input is structure array field

Syntax

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

Description

tf = isfield(S, 'fieldname')examines structureSto see if it includes the field specified by the quoted character vector'fieldname'. Outputtfis set to logical1(true) ifScontains the field, or logical0(false) if not. IfSis not a structure array,isfieldreturnsfalse.

tf = isfield(S, C)examines structureSfor multiple fieldnames as specified in cell array of character vectorsC, and returns an array of logical values to indicate which of these fields are part of the structure. Elements of output arraytfare set to a logical 1 (true) if the corresponding element ofCholds a fieldname that belongs to structureS. Otherwise, logical 0 (false) is returned in that element. In other words, if structureScontains the field specified inC{m,n},isfieldreturns a logical 1 (true) intf(m,n).

Note

isfieldreturnsfalseif thefieldorfieldnamesinput is empty.

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];

isfieldidentifiesbillingas a field of that structure.

isfield(patient,'billing') ans = 1

Example 2 — Multiple Fieldname Syntax

Check structureSfor any of four possible fieldnames. Only the first is found, so the first element of the return value is set totrue:

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

Extended Capabilities

Introduced before R2006a

Was this topic helpful?