Main Content

isfield

Determine if input is structure array field

Description

example

TF = isfield(S,field)returns1iffieldis the name of a field of the structure arrayS. Otherwise, it returns0.

Iffieldis an array that contains multiple names andSis a structure array, thenTFis a logical array that has the same size.

IfSis not a structure array, thenisfieldreturns0.

Examples

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: [0 0.0635 0.1269 0.1904 0.2539 0.3173 0.3808 0.4443 0.5077 ... ] y: [0 0.0634 0.1266 0.1893 0.2511 0.3120 0.3717 0.4298 0.4862 ... ] title: 'y = sin(x)'

Determine if'title'is the name of a field ofS.

TF = isfield(S,'title')
TF =logical1

You can test multiple names in one call to theisfieldfunction by specifying them in a cell array or string array.

field = {'x','y','z','title','error'}; TF = isfield(S,field)
TF =1x5 logical array1 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.

Tips

  • If the input argumentSis an object, thenisfieldalways returns0, even whenfieldis the name of a property.

    To determine if a name is the name of a property of an object, use theispropfunction.

Extended Capabilities

Version History

Introduced before R2006a