Main Content


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



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.


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=2×1 struct array with fields:

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

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

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=3×2 cell array
    {[0 0.0635 0.1269 0.1904 ... ]}    {[0 0.0635 0.1269 0.1904 ... ]}
    {[0 0.0634 0.1266 0.1893 ... ]}    {[1 0.9980 0.9920 0.9819 ... ]}
    {'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

Version History

Introduced before R2006a