MATLAB Function Reference | ![]() ![]() |
Return field names of a structure, or property names of a MATLAB object or Java 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 or a 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 or a Java object.
Examples
mystr(1,1).name = 'alice'; mystr(1,1).ID = 0; mystr(2,1).name = 'gertrude'; mystr(2,1).ID = 1
the command n = field
names(mystr)
yields
n = 'name' 'ID'
In another example, if x
is an object of Java class java.awt.Frame
, the command fieldnames(x)
results in the display
ans = 'width' 'height'
See Also
![]() | fgets (serial) | figflag | ![]() |