isfield - Determine if input is structure array field - MATLAB (original) (raw)
Main Content
Determine if input is structure array field
Syntax
Description
TF = isfield([S](#mw%5F49da869f-baa6-47e9-b0bb-4e1f1531c5b6),[field](#mw%5F7ba47161-d5e5-430e-b3ee-fd4c679bd5be))
returns 1
if field
is the name of a field of the structure array S
. Otherwise, it returns 0
.
If field
is an array that contains multiple names andS
is a structure array, then TF
is a logical array that has the same size.
If S
is not a structure array, then isfield
returns 0
.
Examples
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 0.5712 0.6347 0.6981 0.7616 0.8251 0.8885 0.9520 1.0155 1.0789 1.1424 1.2059 1.2693 1.3328 1.3963 1.4597 1.5232 1.5867 1.6501 1.7136 1.7771 1.8405 1.9040 1.9675 … ] (1×100 double) y: [0 0.0634 0.1266 0.1893 0.2511 0.3120 0.3717 0.4298 0.4862 0.5406 0.5929 0.6428 0.6901 0.7346 0.7761 0.8146 0.8497 0.8815 0.9096 0.9341 0.9549 0.9718 0.9848 0.9938 0.9989 0.9999 0.9969 0.9898 0.9788 0.9638 0.9450 0.9224 … ] (1×100 double) title: 'y = sin(x)'
Determine if 'title'
is the name of a field of S
.
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 = 1×5 logical array
1 1 0 1 0
Input Arguments
Potential field names, specified as a character vector, cell array of character vectors, or string array.
Tips
- If the input argument
S
is an object, thenisfield
always returns0
, even whenfield
is the name of a property.
To determine if a name is the name of a property of an object, use the isprop function.
Extended Capabilities
Usage notes and limitations:
- Cell arrays are not supported for the second argument.
Version History
Introduced before R2006a