This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


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


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



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

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

fields = fieldnames(S)
fields = 3x1 cell array
    {'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 = 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