Tuesday, August 4, 2009

fieldnames

Return field names of a structure, or property names of an object

Syntax

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

Description

names = fieldnames(s) returns a cell array of strings containing the structure field names associated with the structure s.

names = fieldnames(obj) returns a cell array of strings containing the names of the public data fields associated with obj, which is either a MATLAB, COM, or Java object.

names = fieldnames(obj,'-full') returns a cell array of strings containing the name, type, attributes, and inheritance of each field associated with obj, which is either a MATLAB, COM, or Java object.

Examples

Given the structure

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

the command n = fieldnames(mystr) yields

  • n =
    'name'
    'ID'

In another example, if f is an object of Java class java.awt.Frame, the command fieldnames(f) lists the properties of f.

  • f = java.awt.Frame;

    fieldnames(f)
    ans =
    'WIDTH'
    'HEIGHT'
    'PROPERTIES'
    'SOMEBITS'
    'FRAMEBITS'
    'ALLBITS'
    .
    .

No comments:

Post a Comment