fieldnames
结构体的字段名称,或者 Java 或 Microsoft COM 对象的公共字段
说明
示例
返回字段名称和值
创建一个结构体数组。
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
使用 fieldnames
函数返回元胞数组中的字段名称。
fields = fieldnames(S)
fields = 3x1 cell
{'x' }
{'y' }
{'title'}
要返回字段的值,请使用 struct2cell
函数。struct2cell
和 fieldnames
以相同的顺序返回值和字段名称。
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)' }
输入参数
S
— 输入结构体数组
结构体数组
输入结构体数组。
obj
— 输入对象
Java 对象 | Microsoft COM 对象
输入对象,指定为 Java 对象或 Microsoft COM 对象。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
输入必须为结构体。不支持对象。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2006a 之前推出
另请参阅
setfield
| getfield
| isfield
| orderfields
| rmfield
| struct2cell
| properties
| cell2struct
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)