Main Content

fieldnames

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

Description

fields = fieldnames(S) returns the field names of the structure array S in a cell array.

example

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.

Examples

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:
    x
    y
    title

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

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

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.2539 0.3173 0.3808 0.4443 0.5077 0.5712 0.6347 0.6981 0.7616 0.8251 0.8885 0.9520 1.0155 1.0789 1.1424 1.2059 1.2693 1.3328 1.3963 1.4597 1.5232 1.5867 1.6501 1.7136 1.7771 1.8405 1.9040 1.9675 2.0309 2.0944 2.1579 2.2213 2.2848 2.3483 2.4117 2.4752 2.5387 2.6021 2.6656 2.7291 2.7925 2.8560 2.9195 2.9829 3.0464 3.1099 3.1733 3.2368 3.3003 3.3637 3.4272 3.4907 3.5541 3.6176 3.6811 3.7445 3.8080 3.8715 3.9349 3.9984 4.0619 4.1253 4.1888 4.2523 4.3157 4.3792 4.4427 4.5061 4.5696 4.6331 4.6965 4.7600 4.8235 4.8869 4.9504 5.0139 5.0773 5.1408 5.2043 5.2677 5.3312 5.3947 5.4581 5.5216 5.5851 5.6485 5.7120 5.7755 5.8389 5.9024 5.9659 6.0293 6.0928 6.1563 6.2197 6.2832]}    {[                                             0 0.0635 0.1269 0.1904 0.2539 0.3173 0.3808 0.4443 0.5077 0.5712 0.6347 0.6981 0.7616 0.8251 0.8885 0.9520 1.0155 1.0789 1.1424 1.2059 1.2693 1.3328 1.3963 1.4597 1.5232 1.5867 1.6501 1.7136 1.7771 1.8405 1.9040 1.9675 2.0309 2.0944 2.1579 2.2213 2.2848 2.3483 2.4117 2.4752 2.5387 2.6021 2.6656 2.7291 2.7925 2.8560 2.9195 2.9829 3.0464 3.1099 3.1733 3.2368 3.3003 3.3637 3.4272 3.4907 3.5541 3.6176 3.6811 3.7445 3.8080 3.8715 3.9349 3.9984 4.0619 4.1253 4.1888 4.2523 4.3157 4.3792 4.4427 4.5061 4.5696 4.6331 4.6965 4.7600 4.8235 4.8869 4.9504 5.0139 5.0773 5.1408 5.2043 5.2677 5.3312 5.3947 5.4581 5.5216 5.5851 5.6485 5.7120 5.7755 5.8389 5.9024 5.9659 6.0293 6.0928 6.1563 6.2197 6.2832]}
    {[0 0.0634 0.1266 0.1893 0.2511 0.3120 0.3717 0.4298 0.4862 0.5406 0.5929 0.6428 0.6901 0.7346 0.7761 0.8146 0.8497 0.8815 0.9096 0.9341 0.9549 0.9718 0.9848 0.9938 0.9989 0.9999 0.9969 0.9898 0.9788 0.9638 0.9450 0.9224 0.8960 0.8660 0.8326 0.7958 0.7557 0.7127 0.6668 0.6182 0.5671 0.5137 0.4582 0.4009 0.3420 0.2817 0.2203 0.1580 0.0951 0.0317 -0.0317 -0.0951 -0.1580 -0.2203 -0.2817 -0.3420 -0.4009 -0.4582 -0.5137 -0.5671 -0.6182 -0.6668 -0.7127 -0.7557 -0.7958 -0.8326 -0.8660 -0.8960 -0.9224 -0.9450 -0.9638 -0.9788 -0.9898 -0.9969 -0.9999 -0.9989 -0.9938 -0.9848 -0.9718 -0.9549 -0.9341 -0.9096 -0.8815 -0.8497 -0.8146 -0.7761 -0.7346 -0.6901 -0.6428 -0.5929 -0.5406 -0.4862 -0.4298 -0.3717 -0.3120 -0.2511 -0.1893 -0.1266 -0.0634 -2.4493e-16]}    {[1 0.9980 0.9920 0.9819 0.9679 0.9501 0.9284 0.9029 0.8738 0.8413 0.8053 0.7660 0.7237 0.6785 0.6306 0.5801 0.5272 0.4723 0.4154 0.3569 0.2969 0.2358 0.1736 0.1108 0.0476 -0.0159 -0.0792 -0.1423 -0.2048 -0.2665 -0.3271 -0.3863 -0.4441 -0.5000 -0.5539 -0.6056 -0.6549 -0.7015 -0.7453 -0.7861 -0.8237 -0.8580 -0.8888 -0.9161 -0.9397 -0.9595 -0.9754 -0.9874 -0.9955 -0.9995 -0.9995 -0.9955 -0.9874 -0.9754 -0.9595 -0.9397 -0.9161 -0.8888 -0.8580 -0.8237 -0.7861 -0.7453 -0.7015 -0.6549 -0.6056 -0.5539 -0.5000 -0.4441 -0.3863 -0.3271 -0.2665 -0.2048 -0.1423 -0.0792 -0.0159 0.0476 0.1108 0.1736 0.2358 0.2969 0.3569 0.4154 0.4723 0.5272 0.5801 0.6306 0.6785 0.7237 0.7660 0.8053 0.8413 0.8738 0.9029 0.9284 0.9501 0.9679 0.9819 0.9920 0.9980 1]}
    {'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