Determine if input is structure array field
TF = isfield(S,field)
example
TF = isfield(S,field) returns 1 if field is the name of a field of the structure array S. Otherwise, it returns 0.
S
field
1
0
If field is an array that contains multiple names and S is a structure array, then TF is a logical array that has the same size.
TF
If S is not a structure array, then isfield returns 0.
isfield
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: [1x100 double] y: [1x100 double] title: 'y = sin(x)'
Determine if 'title' is the name of a field of S.
'title'
TF = isfield(S,'title')
TF = logical 1
You can test multiple names in one call to the isfield function by specifying them in a cell array or string array.
field = {'x','y','z','title','error'}; TF = isfield(S,field)
TF = 1x5 logical array 1 1 0 1 0
Structure array.
Potential field names, specified as a character vector, cell array of character vectors, or string array.
Usage notes and limitations:
Cell arrays are not supported for the second argument.
fieldnames | getfield | is* | isa | isstruct | orderfields | rmfield | setfield | struct
fieldnames
getfield
is*
isa
isstruct
orderfields
rmfield
setfield
struct
You have a modified version of this example. Do you want to open this example with your edits?