Skip to Main Content Skip to Search
Product Documentation

fieldnames - Field names of structure, or public fields of object

Syntax

names = fieldnames(s)
names = fieldnames(obj)
names = fieldnames(obj,'-full')

Description

names = fieldnames(s) returns a cell array of strings containing the names of the fields in structure s.

names = fieldnames(obj) returns a cell array of strings containing the names of the public properties of obj. MATLAB objects can overload fieldnames and define their own behavior.

names = fieldnames(obj,'-full') returns a cell array of strings containing the name, type, attributes, and inheritance of the properties of obj. Only supported for COM or Java objects.

Examples

Structure Fields

Create a structure array and view its fields.

s(1,1).name = 'alice';
s(1,1).ID = 0;
s(2,1).name = 'gertrude';
s(2,1).ID = 1;

names = fieldnames(s)
names = 
    'name'
    'ID'

Java Object Properties

Create a Java object and view its public properties.

obj = java.lang.Integer(0);
names = fieldnames(obj)
names = 
    'MIN_VALUE'
    'MAX_VALUE'
    'TYPE'
    'SIZE'

See Also

getfield | isfield | orderfields | rmfield | setfield

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS