fieldnames

Field names of structure, or public fields of Java or Microsoft COM object

Syntax

fields = fieldnames(S)
fields = fieldnames(obj,'-full')

Description

example

fields = fieldnames(S) returns the field names of the structure array S in a cell array.

fields = fieldnames(obj,'-full') returns a cell array of character vectors containing the name, type, attributes, and inheritance of the properties of obj. The input argument obj is a Java® or Microsoft® COM object.

Examples

collapse all

Create a structure array.

S(1,1).x = linspace(0,2*pi);
S(1,1).y = sin(S(1,1).x);
S(1,1).title = 'y = sin(x)';
S(2,1).x = linspace(0,2*pi);
S(2,1).y = cos(S(2,1).x);
S(2,1).title = 'y = cos(x)'
S = 2x1 struct array with fields:
    x
    y
    title

Return the field names in a cell array using the fieldnames function.

fields = fieldnames(S)
fields = 3x1 cell array
    {'x'    }
    {'y'    }
    {'title'}

To return the values of the fields, use the struct2cell function. struct2cell and fieldnames return the values and the field names in the same order.

values = struct2cell(S)
values = 3x2 cell array
    {1x100 double}    {1x100 double}
    {1x100 double}    {1x100 double}
    {'y = sin(x)'}    {'y = cos(x)'}

Input Arguments

collapse all

Input structure array.

Input object, specified as a Java object or Microsoft COM object.

Extended Capabilities

Introduced before R2006a